Bri*_*man 3 javascript ajax jquery
我有以下代码:
<script type="text/javascript">
$(document).ready(function()
{
$("#thang").load("http://www.yahoo.com");
$(".SmoothLink").click( function()
{
$("#thang").fadeOut();
$("#thang").load($(this).attr("href"));
$("#thang").fadeIn();
});
});
</script>
<a href="http://www.google.com" id="thelink" class="SmoothLink">click here</a><br /><br />
<div style="border: 1px solid blue;" id="thang">
</div>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是一个快速简单的方法来ajax-ify一个网站,只需在我想要加载到div的某些链接上放一个类.我遇到的问题是正常的锚操作被触发,只是正常重定向到链接href.如何抑制正常的锚定动作?
通常:
$('a').click(function(e) {
//prevent the 'following' behaviour of hyperlinks by preventing the default action
e.preventDefault();
//do stuff
});
Run Code Online (Sandbox Code Playgroud)
要么:
$('a').click(function(e) {
//do stuff
//equivalent to e.preventDefault AND e.stopPropagation()
return false;
});
Run Code Online (Sandbox Code Playgroud)
更多信息:
http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29
上的区别前面的问题return false和e.preventDefault():
event.preventDefault()与return false
| 归档时间: |
|
| 查看次数: |
3598 次 |
| 最近记录: |