jquery脚本执行后刷新回来
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".comment").click(function(){
$(".commentForm").slideToggle("slow");
});
});
</script>
</head>
上面的脚本将从中滑入,但随后浏览器会再次刷新并将其带回原始模式,用户可以看到表单,而不是保持隐藏或滑入的表单。
我已经在 Chrome 和 Mozzilla 两种浏览器中尝试过刷新速度比firefox快。
为什么会发生这种情况是 jquery.js 造成的?
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".comment").click(function(){
$(".commentForm").slideToggle("slow");
});
});
</script>
</head>
this script above will slide in a from but then somehow the browser refresh again and bring it back to original mode where user can see the form instead of staying with the form hided or slided in.
I have tried in two browser Chrome and Mozzilla in Chrome the refresh back is faster than firefox.
why is that happening is the jquery.js causing this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
event.preventDefault();
添加到函数末尾,这将阻止默认函数并避免刷新页面。这不是浏览器问题。
add
event.preventDefault();
to end of your functionthis will prevent the default function and avoid from refreshing the page . and this is not a browser issue .
确保通过从
click
事件处理程序返回false
来取消链接的默认操作:或者:
如果此
.comment
选择器代表 < code>Make sure you cancel the default action of the link by returning
false
from theclick
event handler:or:
If this
.comment
selector represents a<form>
or an anchor and you don't prevent the default action the browser will simply redirect and the javascript might not have time to execute.