2017-04-05 48 views
0

如何在不使用javascript的情況下更改href內的文本?更改沒有ID的href innerHTML?

<a href="member.php?action=profile&uid=0">Owner</a> 
+0

你們是不是要選擇鏈接不使用id屬性或刪除的ID部分href屬性中的url? – Derek

+0

查看下面的答案。 – cosmoonot

回答

0

這是你想要的嗎?

<script type="text/javascript"> 
    function open_fun() { 
    document.getElementById('link').innerHTML = "<a 
    href='javascript:oprn()'>CLOSE</a>"; 
    } 
</script> 

<body> 
<div id='link'><a href='javascript:open()'>OPEN</a></div> 
</body> 
0

Javascript方法:

目標的標籤,更換使用的innerHTML內容。

document.getElementsByTagName('a')[0].innerHTML = "New text!"; 

jQuery的方法:

您可以直接針對a標籤更改鏈接文本。

$('a').html('Hello World'); 

要改變HREF使用本:

$('a').attr("href", "http://www.google.com/"); 
0
<a href="member.php?action=profile&uid=0" onclick="textChanger(this);return false;">Owner</a> 

function textChanger(link){ 
    link.innerHTML = 'YourText'; 
} 

它的測試。您也可以將多個參數傳遞給該函數,即文本/字符串。

0

您可以使用querySelector()方法通過其屬性選擇<a>標籤。

例如:

var tag = document.querySelector('a[href="member.php?action=profile&uid=0"]'); 
if(tag){ 
    tag.innerHTML = "TEXT"; 
} 

演示:

function update(){ 
 
    var tag = document.querySelector('a[href="member.php?action=profile&uid=0"]'); 
 
    if(tag){ 
 
     tag.innerHTML = "TEXT"; 
 
    } 
 
}
<a href="member.php?action=profile&uid=0">Owner</a> 
 

 
<br /><button onclick="update()">Update</button>