我在如此多的頁面中設置了以下鏈接。如何使用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) –