【问题标题】:Update Href of Link button Through Jquery通过 Jquery 更新链接按钮的 Href
【发布时间】:2011-01-06 16:55:09
【问题描述】:

我正在使用链接按钮将页面重定向到我想要的位置,其中包含来自 Jquery 的一些查询字符串值。 链接按钮代码如下:

<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!");
    }
}

我想要做的是它会从复选框中收集所有逗号分隔的值,并将其传递到另一个页面,并将收集的值作为查询字符串。 单击该链接按钮时,它应该带有所有逗号分隔的值并重定向到所需的页面。 请帮助我.. 提前致谢。

【问题讨论】:

    标签: .net jquery redirect href linkbutton


    【解决方案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;
      });
    });
    

    【讨论】:

    • 我想使用锚链接按钮单击事件而不是 location.href。那么让我知道是否有简单的解决方案可用?
    • 我做了一些小改动,现在怎么样?
    【解决方案2】:
    if (s != null) {
      $("@.button#selectAllLink").attr("href", "");
      $("@.button#selectAllLink").attr("href", "/D_ContactSeller.aspx?property=" + s);
    }
    else {
        alert("Select atleast one property to contact!");
    }
    

    希望这会有所帮助:)

    【讨论】:

    • 我只是这样做。但它仍然无法正常工作。有什么我错过了吗?
    • 请删除此代码 onclick="return (this.href=='#');"我认为这会导致问题。
    • 我应该尝试什么而不是 onclick="return (this.href=='#');
    • 当你第一次点击这个链接然后它会在点击事件上返回true,当你点击链接改变href值之后你的java脚本返回(this.href=='#')将返回 false,所以它不起作用所以试试吧
    • 它不起作用,实际上框架打开时提到正在加载...并且没有 url 更改。问题是页面没有被重定向。
    猜你喜欢
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 2012-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多