Bar*_*din 8 each jquery href attr
我试图用每种方法改变href,
HTML:
<a href="#/news">News</a>
<a href="#/news/detail">Detail</a>
<a href="#/sport">Sport</a>
<a href="#/sport/football">Football</a>????????????
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('a').each(function() {
$(this).attr('href').replace('#/',''); //tried to erase #/ from all hrefs
});?
Run Code Online (Sandbox Code Playgroud)
Jar*_*Par 15
您发布的代码将获得值,string然后正确replace的值,但它会立即丢弃结果.您需要将替换值传递给attr.请尝试以下方法
$('a').each(function() {
var value = $(this).attr('href');
$(this).attr('href', value.replace('#/',''));
});?
Run Code Online (Sandbox Code Playgroud)
var href = $(this).attr('href');
$(this).attr('href', href.replace('#/',''));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28301 次 |
| 最近记录: |