标签jquery绑定oclick事件(包含ajax操作)后,点击时间ajax提交两次问题

原JS代码
$('#id').click(
function(event) {
        $.ajax({
		type:"post",
		url:"",
		data:null,
		dataType:"json",
		async:false,
		success:function(data){
		}
	});
});


发现非button标签会执行两次ajax事件。经查是标签之间的传递性导致的。只需要加一行代码即可。
$('#id').click(
function(event) {
        $.ajax({
		type:"post",
		url:"",
		data:null,
		dataType:"json",
		async:false,
		success:function(data){
		}
	});
        //添加代码
        event.stopPropagation();
});


参考文章: http://www.365mini.com/page/jquery-event-stoppropagation.htm

猜你喜欢

转载自fugmaster.iteye.com/blog/2296432
今日推荐