Javascript 等效于onclick=";更新“本文件”;在jquery中?(调用函数)
我有一个html函数:Javascript 等效于onclick=";更新“本文件”;在jquery中?(调用函数),javascript,html,function,jquery,Javascript,Html,Function,Jquery,我有一个html函数: <script> function update_x(obj) { ... } </script> 及 两者都不起作用…这将相当于: $('.aaa').click(function () { update_x(this); }); 但你不需要用这个。只需将函数更改为 function update_x(event_obj) { // 'this' will be the clicked object automatic
<script>
function update_x(obj) {
...
}
</script>
及
两者都不起作用…这将相当于:
$('.aaa').click(function () {
update_x(this);
});
但你不需要用这个。只需将函数更改为
function update_x(event_obj) {
// 'this' will be the clicked object automatically
// plus, you have further info in the event object
}
$('.aaa').click(update_x);
确保
$('.aaa')。在DOM中存在类为“aaa”的元素后调用click(update_x)
。您可以将该代码包装在文档中。就绪处理程序,或使用。$('.aaa')。单击(更新)
可以工作,把它放在DOM就绪处理程序中,或者放在正文结束标记
之前,也许您也可以提到document.ready。也许这可能是他第一个片段不起作用的另一个原因,他添加了一条关于这一点的评论,但我相信他的第一个片段不起作用,因为他试图在监听器中阅读obj
,而不是this
。它再简单不过了,而且很有效。谢谢贝法雷托:)
$('.aaa').click(function () {
update_x(this);
});
function update_x(event_obj) {
// 'this' will be the clicked object automatically
// plus, you have further info in the event object
}
$('.aaa').click(update_x);