我是jQuery的新手,当我们按下以下代码上的按钮时,我不知道如何获取事件。请帮我。
<div class="key">
<div class="buttonWrapper">
<span data-i18n="keypad.one" class="button i18n"></span>
</div>
</div>
答案 0 :(得分:0)
如果静态加载,请使用类似click
函数的内容:
// Wait till the page is loaded and then do the following...
$(document).ready(function () {
// Attach a click handler on the element with the class button.
$(".button").click(function () {
// The code to be executed when the button is clicked.
alert("Hi");
});
});
或者,如果它本质上是动态的,请找到一个静态父级并委托事件:
// Wait till the page is loaded and then do the following...
$(document).ready(function () {
$("body").on("click", ".button", function () {
// The code to be executed when the button is clicked.
alert("Hi");
});
});
请参阅:
答案 1 :(得分:0)