2015年5月18日 星期一

Multiple CSS and jquery

Problem Description

How does the meaning in class="errorMessage active"
HTML Code
<span class="errorMessage active">Invalid</span>


CSS Code and why the .active after the .errorMesage
.errorMessage{
display: none;
color: red;
margin-left: 10px;
}
.errorMessage.active {
display: inline-block;
border: 1px solid #e6e6e6;
padding: 0 5px;
background: #ffdae0;
border-radius: 3px;
}

Jquery code
$('.IncludeSnRNA').on('change', function(){
    if($(this).is(":checked")){
    $('.errorMessage').addClass("active");
    $('.IncludeSnRNA').val('t');
    }else {
    $('.errorMessage').removeClass("active");
    $('.IncludeSnRNA').val('f');
    }
    });



Solution

Target an element that has all of multiple classes
and means the active class of errorMessage class is use as constraint to that the subject is errorMessage

2015年5月4日 星期一

Jquery Deffer method

Introduction Basic content

Ajax: Asynchronous Java script and XML
JSON: Using string representation for an object 
jqXHR object:  is jquery XML HTTP object which represent as $.ajax
JSONP: Give a strategy to access cross domain data
 
                    Subject of Deffer function
Goal: 
It will let programmer make a asyn-like calling mechanism
and often use in nested ajax calling to avoid to nested content.

Event trigger:
In the process, declare the deffer start .deffer().
Then, you should write deffer.resolve() mean it success, or deffer.reject() mean fail in handle process.
Finally, you return it by .promise();

Event Handle:
Client code can handle it by .then(callback1, [callback2]) method after it use the Event trigger method,


Ref:
ajax-deferreds tutorial
jquery deferred-object function
jquery-deferred-object chinese