显示jQuery的序列号HREF

问题描述:

我展示我的jQuery的ID与此显示jQuery的序列号HREF

// jquery code 
active = $('#rate_slider li.active').attr('id'); 
//jquery code 

没有我送这个活跃在HREF链接:

<a href="javascript:void(0);" class="content" onclick="getdata('data.php?id=active','send');">submit</a> 

注:ID =主动/是产生jquery id

感谢您的帮助。

+0

澄清;你问为什么当你调用'getdata()'时,'active'变量没有被替换? – Tejs 2011-12-29 16:19:15

喜欢的东西:

"getdata('data.php?id='+active,'send');" 

根据您的问题的标题,我想这可能是你想要

<a id="yourLink" class="content">submit</a> 

然后呢:

active = $('#rate_slider li.active').attr('id'); 
$("#yourLink").attr("href", "data.php?id=" + active); 

或者,如果你不” t在你的href中需要这个活动值,但实际上当链接被点击时确实想要调用getData,那么这个应该工作

<a id="yourLink" href="javascript:void(0);" class="content">submit</a> 

active = $('#rate_slider li.active').attr('id'); 
$("#yourLink").click(function() { 
    getdata('data.php?id=' + active,'send'); 
} 

你就像在你的榜样字符串处理用,你需要把它当作一个变量。我甚至没有肯定会工作,因为通常将jQuery包装在匿名函数中。所以你的内联onclick声明可能会失败。我会这样做,而不是。如果你使用的是jQuery 1.7+,你应该使用prop而不是attr

<!-- dont set href to void. just set it to a hash instead. dont set onclick inline --> 
<a href="#" class="content">submit</a> 

 

//you may need to add var to active. you didnt post enough code so cant know for sure 
var active = $('#rate_slider li.active').prop('id'); 

//use jquerys click handlers instead of inline onclick statements 
$('#yourLink').click(function() { 
    getdata('data.php?id' + active,'send'); 
    return false; //prevent link navigation 
}); 

现在想起来,我相信你想点击时提交的,以获得当前活动的列表项。在这种情况下,您希望在您的点击事件中进行该调用。

$('#yourLink').click(function() { 
    var active = $('#rate_slider li.active').prop('id'); 
    getdata('data.php?id' + active,'send'); 
    return false; //prevent link navigation 
});