我想使用jQuery手机更改href,我尝试了一些代码示例,例如:
$("a[href='http://www.google.com/']").attr('href', 'http://www.live.com/');<li><a data-ajax="false" href="http://www.google.com" >Navigate</a></li>和
$("#address").append("href", "http://cupcream.com");<li><a data-ajax="false" id="address" href="http://www.google.com" >Navigate</a></li>但是什么也没发生。
有什么问题吗,这不是jQuery手机中的一些bug吗?
发布于 2013-05-12 22:30:22
您需要向"a“元素添加属性rel="external"或data-ajax="false",以便不通过Ajax管理链接。官方文档here。
发布于 2013-09-21 02:17:09
只改变href属性对我不起作用。我必须同时更改文本和属性href,这很好用。在Chrome、火狐和IE10上测试过。
$('#campuslink').text('http://www.google.com');
$('#campuslink').attr('href','http://www.google.com');这为我解决了这个问题。
发布于 2015-04-22 07:53:41
如果您没有data-ajax="false",则不能通过jquery attr函数更改链接。我看到你有它,但我要提一下,以备将来搜索之用。
一旦有了链接,就可以像这样更改链接:$('a[href='http://www.google.com/']').attr('href','http://www.live.com/');
我建议通过在测试用例上执行“hide()”来确保选择器按预期工作。
https://stackoverflow.com/questions/5623201
复制相似问题