【发布时间】:2016-03-14 15:48:22
【问题描述】:
当我点击按钮时,它会显示Bruce Wayne is Batman。在 jQuery 的最后一行中,对于“click”函数,如果我传递参数“guy”,则 jQuery 不会运行,但如果我不传递参数,我会得到 undefined。我究竟做错了什么?提前致谢。
$("div").on('click', 'button', click(guy));
jsFiddle链接,HTML和JS如下。
https://jsfiddle.net/wrj5w1Lk/
<div>
<button>
Click Me! Click Me!
</button>
<p>Hello</p>
</div>
$(document).ready(function() {
var Person = function(first, last, secret) {
this.first = first;
this.last = last;
this.secret = secret;
}
var guy = new Person("Bruce", "Wayne", "Batman");
var click = function(person) {
$(this).closest('div').find('p').text(person.first + " " + person.last + " is " + person.secret);
};
$("div").on('click', 'button', click(guy));
});
【问题讨论】:
-
在您提出新问题之前请user the search。
-
会的。有点太激动了,并没有想到要搜索论坛。
标签: javascript jquery html