Контроллер
1 2 3 4 |
public ActionResult OnClick() { return View(); } |
Представление
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
@{ ViewBag.Title = "OnClick"; } <h2>OnClick</h2> <button id="bind">bind</button> <button id="on">on</button> <button id="delegate">delegate</button> <button id="one">one</button> <script src='@Url.Content("~/Scripts/jquery-1.10.2.min.js")' type="text/javascript"></script> <script> $(function () { //bind $('#bind').bind('click', function () { alert('it is a bind method, now it will be unbinded'); $('#bind').unbind(); }); //on $('#on').on('click', function () { alert('it is a bind method, now it will be off'); $('#on').off(); }); //delegate $('body').delegate('#delegate', 'click', function () { alert('it is a delegate method, now it will be undelegated'); $('body').undelegate('#delegate', 'click'); }); //one $('#one').one('click', function () { alert('it is one function, it will work one time'); }); }); </script> |