读书人

jQuery若干有关问题

发布时间: 2012-11-25 11:44:31 作者: rapoo

jQuery若干问题.
1.每次点击后依次调用函数。返回值:jQuerytoggle(fn, fn2, [fn3, fn4, ...])

$("#adv_search").toggle(function(){
$(this).addClass("btn_hover");
//$("#sreachArea").show();
document.getElementById("adv_search").style.display = 'block';
},function(){
$(this).removeClass("btn_hover");
//$("#sreachArea").hide();
document.getElementById("adv_search").style.display = 'none';
})



$("p").toggleClass("selected");

$(this).toggleClass("class");



2.一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法返回值:jQueryhover(over, out)
$("td").hover(
function () {
$(this).addClass("hover");
},
function () {
$(this).removeClass("hover");
}
);

3.jQuery.ajax([options])中同步提交\异步提交.

async: Boolean(默认: true) 默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。

$.ajax({
    type: requestType,
    timeout:5000,
    url: requestUri,
    async: false,
    data: param,
     success: function(data, textStatus){
         //...
     },
     error: function(XMLHttpRequest, textStatus){
        //...
     },
     complete:function(XHR, TS){
        //...
     }
});

若用异步提交,在error、success或complete中再次提交时,XMLHttpRequest.status和XMLHttpRequest.readyStatus为0(尚未初始化成功),导致获取再次提交返回信息失败.



XMLHttpRequest.readyState 有0到4的值,分表示不同的求:

0 = 未初始化的(uninitialized),呼叫open()
1 = 入中(loading),呼叫open(),呼叫send()
2 = 已入(loaded),呼叫send(),求header/status好
3 = 互中(interactive),正在伺服器互中
4 = 求完成(completed),完成求

XMLHttpRequest.status

100 Continue
101 Switching protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Suitable
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported




public static String toGMT(Date date) {SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.US);Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));format.setCalendar(cal);return format.format(date);}

读书人网 >Web前端

热点推荐