【问题标题】:JSON Issue with API HREFAPI HREF 的 JSON 问题
【发布时间】:2015-01-25 11:47:35
【问题描述】:

所以我试图让 href 代码成为一个可点击的按钮。到目前为止,我只是想把它作为一个链接!

代码如下

$("table").append("<tbody><tr><td>"+title+"</td><td><a href='&quot;+href+&quot;'></a></td></tr></tbody>");

JSON 拉回了 Href 链接,我想要的只是有一个显示 link 的表格按钮,并使用来自 json 的链接重定向页面。

山姆

【问题讨论】:

    标签: javascript jquery json jsonp


    【解决方案1】:

    你需要做两件事:

    1. 创建一个按钮元素
    2. 附加一个重定向页面的点击事件
      var button = "<button class='redirect-button' data-url='"+href+"'>Link</button>";
      $("table").append("<tbody><tr><td>"+title+"</td><td>"+button+"</td></tr></tbody>");
      $("table").find(".redirect-button").click(function(){
           location.href = $(this).attr("data-url");
      });
    

    【讨论】:

    • 哇,这么简单? TYVM!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 2015-03-02
    • 2012-08-21
    相关资源
    最近更新 更多