ITS*_*ion 2 html javascript jquery href attr
我试图href通过jQuery 改变,但我不知道为什么它不工作...
$(document).ready(function () {
var oldurl = $('`http://google.com`');
var newurl = $('`http://yahoo.com`');
$('a[href="' + oldurl + '"]').attr('href', newurl);
// it's not working too...
//$('a[href="http://google.com"]').attr('href', 'http://yahoo.com');
// it's not working too...
//$('.mylink').attr('href', newurl);
});
Run Code Online (Sandbox Code Playgroud)
您只需要:
var oldurl = 'http://google.com';
var newurl = 'http://yahoo.com';
$('a[href="' + oldurl + '"]').attr('href', newurl);
Run Code Online (Sandbox Code Playgroud)
网址必须是字符串而不是jQuery对象,而您忘记关闭方括号.
| 归档时间: |
|
| 查看次数: |
20343 次 |
| 最近记录: |