Home > Web Front-end > JS Tutorial > Live method and $.browser method usage code under JQuery_jquery

Live method and $.browser method usage code under JQuery_jquery

WBOY
Release: 2016-05-16 18:25:53
Original
912 people have browsed it

复制代码 代码如下:

$(function(){
Ajaxload("?Uid=1<%= Yan.GET_Dict(id, 8, TableName)%>")
$("#ThreeM a:first").addClass("addBg");
$(".pageP2 a").live("click",function(){var NewUrl=$(this).attr("href");if(jQuery.browser.msie){var IE=$.browser.version;if(IE=="7.0" || IE=="6.0"){NewUrl="?" NewUrl.split('?')[1]}};Ajaxload(NewUrl);return false;});/*return false阻止默认a标签跳转,改用ajax请求*/
$("#ThreeM a").click(function(){
if(!$(this).hasClass("addBg")){$("#ThreeM a").removeClass("addBg");$(this).addClass("addBg")}
var Url="?Uid=1" $(this).attr("id");
Ajaxload(Url);
})
})
function Ajaxload(parm)
{
$.ajax({
type: "GET",
url: "/stus/3th.aspx" parm,
cache: false,
beforeSend:function(){$("#Three").html("
  load...
")},
success: function(msg){
$("#Three").html(msg);
},
error:function(){$("#Three").html("Load failure...")}
});
}

jQuery.browser方法有如下参数,返回true或者false: 
safari
opera
msie
mozilla 
是这里引用浏览器判断,是由于在IE6.0和7.0中a标签里的href="?Uid="获取过来是整个地址,不知道为什么。就用split截取了。。。

$.live()方法是1.3.2新增的的函数,在1.4.1可以支持自定义事件。具体查api吧。。。

另外关于live方法的冒泡:

ajax提交获取过来的动态生成的a标签,用Live()方法绑定了click事件。第二次查询时会执行2次click事件,冒泡了。用one()方法的话,点击一次就失效了。

最后用bind方法,在提交按钮cilick的时候,Unbind()取消绑定。就可以了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template