![](/img/trans.png)
[英]How Do I Replace/Change The Heading Text Inside <h3></h3>, Using jquery?
[英]How do I change text inside an element using jquery?
我對 javascript 很陌生,我正在嘗試更改下面元素中的文本,但是它不起作用
<div id='text'></div>
這是我正在使用的查詢,console.log 有效,但 text() 函數無效。
d3.json('/data', function(error, closure_data) {
$('.dropdown-item').click(function() {
if ($(this).attr('value') == '1') {
console.log('1')
text = d3.select('#text')
$(text).text('1');
}
});
})
盡管 Manjuboyz 的回答有效,但我還是按照我的同事和這篇文章中一些人的建議,刪除了我的 jquery 腳本並只使用了 d3。 這是結果代碼。
d3.json('/data', function(error, closure_data) {
var btn = d3.select('.dropdown-item')
btn.on('click', function() {
d3.select('#text').text('1')
})
});
你可以使用這樣的東西:
$("#btnClick").click(function(){ $("div").text("your value in DIV"); });
div { color: red; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type='submit' id="btnClick" value="ClickMe"> <div id ="textDIv"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.