Definition and usage
The bind () method adds one or more event handlers to the selected element, and specifies the function to run when the event occurs.
Instance 1 (one event)Remember to replace the JS reference address
When you click the mouse, hide or show the P element:
<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Bind ("click", Function () {
$ ("P"). Slidetoggle ();
});
});
</script>
<body>
<p>this is a paragraph.</p>
<button> Click here </button>
</body>
Instance 2 (three events)
<script type= "Text/javascript" src= "/jquery/jquery.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("button"). Bind ({
Click:function () {$ ("P"). Slidetoggle ();},
Mouseover:function () {$ ("body"). CSS ("Background-color", "Red");},
Mouseout:function () {$ ("body"). CSS ("Background-color", "#FFFFFF");}
});
});
</script>
<body>
<p>this is a paragraph.</p>
<button> Click here </button>
</body>
JQuery Event-Bind () method