Jquery 奇怪的行为 - object.click
请看一下这段代码:
<!DOCTYPE html>
<html lang="es">
<head runat="server">
<title>Main - Annex7</title>
<meta charset="utf-8" />
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(load);
function load() {
var objectX= $("#objectX")
objectX.click(alert('auch'));
}
</script>
当我点击 objectX 时,“click”事件不应该被触发吗??? 但是当我加载文档时会触发此警报...
我有点困惑,请提供任何帮助,我们将非常感激。
提前致谢...
Please take a look on this code:
<!DOCTYPE html>
<html lang="es">
<head runat="server">
<title>Main - Annex7</title>
<meta charset="utf-8" />
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(load);
function load() {
var objectX= $("#objectX")
objectX.click(alert('auch'));
}
</script>
Should not the 'click' event get fired when I do click on objectX???
But this alert is fired when I load the document...
I´m a little confused, please any help would be very well received.
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将点击事件更改为:
您需要将一个函数传递到事件中,
如果您只传递一个操作,您将收到错误
change the click event to:
you need to pass a function into the event,
if you just pass an action you will get errors
您需要将其包装在一个函数中,例如匿名函数......
You need to wrap it in a function, such as an anonymous one...