javascript和jquery修改a标签的href属性
内容摘要
javascript: 复制代码 代码如下: document.getElementById("myId").setAttribute("href","www.xxx.com"); document.getElementById("myId").href = "www.xxx.com"; jquery:
文章正文
javascript:
document.getElementById("myId").setAttribute("href","www.xxx.com");
document.getElementById("myId").href = "www.xxx.com";
jquery:
$("#myId").attr("href","www.xxx.com");
复制代码 代码如下:
document.getElementById("myId").setAttribute("href","www.xxx.com");
document.getElementById("myId").href = "www.xxx.com";
jquery:
复制代码 代码如下:
$("#myId").attr("href","www.xxx.com");
代码注释