通过jquery更新链接按钮Href
问题描述:
我正在使用链接按钮将页面重定向到我想要的位置,并使用来自Jquery的一些查询字符串值。 链接按钮的代码如下:通过jquery更新链接按钮Href
<td>
<a id="selectAllLink" class="button" rel="nofollow ibox&width=800&height=400&title=Contact Now"
href="#" onclick="return (this.href=='#');">Contact Selected</a>
</td>
而且Jquery的,这将创造我的链接按钮的点击事件/更新的链接如下:
function CotactSelected() {
var a = [];
var n = $("td.title_listing input:checked");
var s = "";
n.each(function() {
a.push($(this).val());
});
var s = a.join(',');
if (s != null) {
$("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s);
}
else {
alert("Select atleast one property to contact!");
}
}
什么,我想要做的就是它将从复选框中收集所有逗号分隔值,并将该值作为查询字符串传递给另一个页面。 单击该链接按钮时,它应携带所有逗号分隔值并重定向到所需的页面。 请帮助我.. 在此先感谢。
答
使用它来代替你的函数CotactSelected
$(function() {
$('#selectAllLink').each(function() {
var a = [];
var n = $("td.title_listing input:checked");
var s = "";
n.each(function() {
a.push(this.value);
});
s = a.join(',');
if (a.length > 0)
this.href= "/D_ContactSeller.aspx?property=" + s;
else
this.href = 'javascript:alert("Select at least one property to contact!");';
return false;
});
});
答
if (s != null) {
$("@.button#selectAllLink").attr("href", "");
$("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s);
}
else {
alert("Select atleast one property to contact!");
}
希望这有助于:)
我想使用Anchor Link Button Click事件不在location.href。 所以让我知道是否有简单的解决方案可用? – Sanju 2010-01-20 09:45:32
我做了一些小的改动,现在怎么样? – 2010-01-20 10:00:32
是的,现在它工作。谢谢卡拉... – Sanju 2010-02-03 07:16:05