.bind( eventType [, eventData], handler(eventObject))
<input id="BtnFirst"type="button"value="Click Me"/>
<script>
$(function () {
$("#BtnFirst").bind("click",function(){
alert("Hello World");
});
})
</script>
<div>
<input id="BtnFirst"type="button"value="Click Me"/></div>
<div id="TestDiv"style=" width:200px; height:200px; display:none; ">
</div>
<script>
$(function () {
$("#BtnFirst").bind("click", function () {
alert("Hello World");
}).bind("mouseout", function () {
$("#TestDiv").show("slow");
});
})
</script>
<style>
p {background:yellow;font-weight:bold;cursor:pointer;3 padding:5px;}
p.over {background:#ccc;}
span {color:red;}
</style>
<p>Click or double click here.</p>
<span></span>
<script>
$("p").bind("click", function(event){
var str = "( " + event.pageX + ", " + event.pageY + " )";
$("span").text("Click happened! " + str);
});
$("p").bind("dblclick", function(){
$("span").text("Double-click happened in " + this.nodeName);
});
$("p").bind("mouseenter mouseleave", function(event){
$(this).toggleClass("over");
});
</script>
<body onclick="MyBodyClick()">
<div onclick="MyClickOut()">
<div onclick="MyClickInner()">
<span id="MySpan">I love JQuery!! </span>
</div>
</div>
<span id="LooseFocus">失去焦点</span>
</body>
<script>
function MyClickOut() {
alert("outer Div");
}
function MyClickInner() {
alert("Inner Div");
}
function MyBodyClick() {
alert("Body Click");
}
var foo = function () {
alert("I'm span.");
}
$(function () {
$("#MySpan").bind("click", foo);
})
$(function () {
$("#LooseFocus").unbind("click", foo);
})
</script>
one(type,[data],fn)
bind : function(type, data, fn) {
return type == "unload" ? this.one(type,data,fn) : this.each(function(){
//fn || data, fn && data实现了data参数可有可无
jQuery.event.add(this, type, fn || data, fn && data);
});
}
one : function(type, data, fn) {
var one = jQuery.event.proxy(fn || data, function(event) {
jQuery(this).unbind(event, one);
return (fn || data).apply(this, arguments);
//this->当前的元素
});
return this.each(function() {
jQuery.event.add(this, type, one, fn && data);
});
}
<body onclick="MyBodyClick()">
<div onclick="MyClickOut()">
<div onclick="MyClickInner()">
<span id="MySpan">
I love JQuery!!
</span>
</div>
</div>
</body>
<script type="text/javascript">
function MyClickOut() {
alert("outer Div");
}
function MyClickInner() {
alert("Inner Div");
}
function MyBodyClick() {
alert("Body Click");
}
$(function () {
$("#MySpan").bind("click", function (event) {
alert("I'm span");
event.stopPropagation();
});
</script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有