2010-01-19 139 views
0

我正在使用鏈接按鈕將頁面重定向到我想要的位置,並使用來自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!"); 
    } 
} 

什麼,我想要做的就是它將從複選框中收集所有逗號分隔值,並將該值作爲查詢字符串傳遞給另一個頁面。 單擊該鏈接按鈕時,它應攜帶所有逗號分隔值並重定向到所需的頁面。 請幫助我.. 在此先感謝。

回答

1

使用它來代替你的函數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; 
    }); 
}); 
+0

我想使用Anchor Link Button Click事件不在location.href。 所以讓我知道是否有簡單的解決方案可用? – Sanju 2010-01-20 09:45:32

+0

我做了一些小的改動,現在怎麼樣? – 2010-01-20 10:00:32

+0

是的,現在它工作。謝謝卡拉... – Sanju 2010-02-03 07:16:05

0
if (s != null) { 
    $("@.button#selectAllLink").attr("href", ""); 
    $("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s); 
} 
else { 
    alert("Select atleast one property to contact!"); 
} 

希望這有助於:)

+0

我就是這麼做的唯一。 但它仍然無法正常工作。 有什麼我錯過了嗎? – Sanju 2010-01-19 09:12:04

+0

請刪除此代碼 onclick =「return(this.href =='#');」 我認爲這會導致問題。 – chirag 2010-01-19 09:41:15

+0

我應該嘗試,而不是onclick =「返回(this.href =='#'); – Sanju 2010-01-20 09:42:21