【问题标题】:Changing the href attribute on checked更改选中的 href 属性
【发布时间】:2011-03-05 22:55:26
【问题描述】:

我正在处理一个包含单选按钮组的网页。

当其中一个按钮被选中时,我需要更改链接元素的 href 属性(使用不同的 CSS 文件),如何使用 Java 脚本和 html 来做到这一点?

我试过 getElementById() 但 innerHtml 属性没有帮助,你有什么简单的解决方案吗?

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    这应该可行:

    document.getElementById('myStylesheet').href = 'http://example.com/new/href/link';
    

    【讨论】:

      【解决方案2】:
      var input = document.getElementById("inputid");
      if (input.checked){
      var aElem = document.getElementById("aid");
      aElem.href = "newurl";
      }
      

      【讨论】:

        猜你喜欢
        • 2014-07-21
        • 2018-10-30
        • 2015-07-16
        • 1970-01-01
        • 1970-01-01
        • 2012-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多