【发布时间】:2014-08-14 11:49:26
【问题描述】:
我正在使用此代码;
if ($forum['type'] != 'c' && !$forum['linkto'] && $forum['posts'])
{
$forum['collapsed_image'] = '<div class="expcolimage"><a href="javascript:void(0);" id="forum_name" fid="'.$fid.'" title="Double click here to see latest threads of this section."><img src="images/collapse_collapsed.gif" id="ann_'.$forum['fid'].'_img" class="expander" alt="[-]" title="[-]" /></a></div>';
}
else
{
$forum['collapsed_image'] = '';
}
这是我的 jquery 代码;
jQuery(document).ready(function($){
$('a[id^="forum_name"]').on('click', function (e){
e.preventDefault();
var fid = $(this).attr("fid");
$.ajax(
{
type : "post",
dataType: "html",
url : "misc.php?action=forum_threads&fid="+fid,
cache: false,
success : function(response)
{
$("#forum_threads_"+fid).stop().slideToggle("fast").html(response);
}
});
});
});
现在,当您双击上面的链接时,它的作用是运行 jquery 代码并显示结果。我不想这样做,所以我只能单击一次来运行 jquery 代码以显示结果。如何实现?
谢谢!
【问题讨论】:
-
你用
e.preventDefault()做什么? -
@Arun:代码很好,我问怎么弄,一键就可以让代码运行而不是点击两下??
-
@user2854563 因为你不需要它。如果您删除 href 属性,您也不会被重定向。
标签: javascript php jquery slidetoggle