这里有一个简单的问题
是否有方法可以更改文本 "click here"?
<a id="a_tbnotesverbergen" href="#nothing">click here</a>
在这个链接中
Richard这里有一个简单的问题
是否有方法可以更改文本 "click here"?
<a id="a_tbnotesverbergen" href="#nothing">click here</a>
在这个链接中
Richard你需要使用jQuery的text()函数。它的作用是:
获取所有匹配元素的合并文本内容。
结果是一个包含所有匹配元素的合并文本内容的字符串。此方法适用于HTML和XML文档。不能用于输入元素。对于输入字段文本,请使用val属性。
例如:
Find the text in the first paragraph (stripping out the html), then set the html of the last paragraph to show it is just text (the bold is gone).
var str = $("p:first").text(); $("p:last").html(str);
Test Paragraph.
Test Paragraph.
使用您的标记,您需要执行以下操作:
$('a#a_tbnotesverbergen').text('new text');
它将会导致
<a id="a_tbnotesverbergen" href="#nothing">new text</a>
$('#a_tbnotesverbergen').text('My New Link Text');
或者$('#a_tbnotesverbergen').html('My New Link Text or HTML');
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<div id="divClickHere">
<a id="a_tbnotesverbergen" href="#nothing">click here</a>
</div>
那么你应该编写这个 jQuery 代码:
<script type="text/javascript">
$(document).ready(function(){
$("#a_tbnotesverbergen").click(function(){
$("#divClickHere a").text('Your new text');
});
});
</script>
获取原始链接文本的代码如下:
我使用:
$("#sec1").text(Sector1);
where
Sector1 = 'my new link text';
来自W3 Schools的HTML DOM更改:如果您查看第三个示例,它展示了如何更改链接中的文本,“点击这里”。 示例:
<a id="a_tbnotesverbergen" href="#nothing">click here</a>
JS:
var element=document.getElementById("a_tbnotesverbergen");
element.innerHTML="New Text";
在 JavaScript 中尝试这个
document.getElementById("22IdMObileFull").text ="itsClicked"