通过bind()方法绑定
<body>
<input id="input" type="button" value="button" class="btn" />
<script>
第一种:
$(function(){
$("#input").bind("click",function(){
$(this).attr("disabled","disabled"); //按钮不可用
});
});
第二种:
$(function(){
$("#input").bind("click mouseout",function(){
$(this).attr("disabled","disabled"); //按钮不可用
});
});
</script>
</body>
通过映射绑定不同的事件:
<body>
第三种:
<div>姓名:<input type="text" class="txt" /></div>
<div id="divTip" class="clsTip"></div>
<script>
$(function(){
$(".txt").bind({ focus: function() {
$("divTip").show().html("执行的是focus事件“);
},
change: function() {
$("#divTip").show().html("执行的是change事件“);
});
});
第四种:
$(function(){
var message = "执行的是focus事件“;
$(".txt").bind("focus", {msg:message},function(event) {
$("#divTip").show().html(event.data.msg);
});
message ="执行的是change事件“;
$(".txt").bind("change", {msg: message}, function(event) {
$("#divTip").show().html(event.data.msg);
});
</script>
</body>