我在如此多的页面中设置了以下链接。如何使用jQuery查找和替换一些内容?
以下是其中有一些代码.IE PHP文件:
输入:
<a href="someurl/someotherfile.html"> Some Other file </a>
<a href="someurl/someotherfile1.html"> Some Other file1 </a>
<p><a href="someurl/someotherfile2.html"> Some Other file2 </a></p>
<div><a href="someurl/someotherfile2.html"> Some Other file2 </a></div>
<span><a href="someurl/someotherfile2.html"> Some Other file2 </a></span>
输出:
<a href="someurl/someotherfile.php"> Some Other file </a>
<a href="someurl/someotherfile1.php"> Some Other file1 </a>
<p><a href="someurl/someotherfile2.php"> Some Other file2 </a></p>
<div><a href="someurl/someotherfile2.php"> Some Other file2 </a></div>
<span><a href="someurl/someotherfile2.php"> Some Other file2 </a></span>
现在,我想改变HTML到PHP扩展在HREF属性。无需修改php代码。
我试过下面的代码,但它不起作用。注意到在这个代码中发生。
$('a').each(function() {
$(this).html($(this).html().replace(".php", '.html'));
});
是什么问题? –
[Jquery在链接上更改扩展名]的可能的重复](http://stackoverflow.com/questions/37718477/jquery-change-extension-on-link-on-fly) –