$('span').bind("click", funciton(event){ //event : 事件对象
var txt = $('#msg').html()+"some spans have been actived
";
$('#msg').html(txt);
event.stopPropagation(); //停止事件冒泡
});
用event.preventDefault();来阻止默认行为 (比如点击提交表单,验证表单内容,不符合条件,要阻止提交(默认行为)。
$("#sub").bind("click", function(event){
var username = $("#username").val(); //get the input value
if(username == ""){
$("#msg").html("Input can't be empty.
"); //提示信息
event.preventDefault(); //阻止默认行为
}
});
also the event.stopPropagation() and event.preventDefault() can be changed to return false;
No comments:
Post a Comment