我怎样才能做到以下几点:
document.all.regTitle.innerHTML = 'Hello World';
使用jQuery哪里regTitle是我的div id?
我怎样才能做到以下几点:
document.all.regTitle.innerHTML = 'Hello World';
使用jQuery哪里regTitle是我的div id?
当前回答
如果你有一个jQuery对象,你想渲染而不是现有的内容:然后只是重置内容并追加新的。
var itemtoReplaceContentOf = $('#regTitle');
itemtoReplaceContentOf.html('');
newcontent.appendTo(itemtoReplaceContentOf);
Or:
$('#regTitle').empty().append(newcontent);
其他回答
$("#regTitle")[0].innerHTML = 'Hello World';
var abc = document.getElementById("regTitle");
abc.innerHTML = "Hello World";
jQuery有几个函数与文本工作,如果你使用text()一个,它将为你做的工作:
$("#regTitle").text("Hello World");
此外,你可以使用html()代替,如果你有任何html标签…
例子 $(document).ready(function() { $ (' .msg ') . html(“hello world”); }); <!DOCTYPE html > < html > < >头 < script src = " https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js " > < /脚本> > < /头 身体< > < div class = "味精" > < / div > 身体< / > < / html >
以下是你的答案:
//This is the setter of the innerHTML property in jQuery
$('#regTitle').html('Hello World');
//This is the getter of the innerHTML property in jQuery
var helloWorld = $('#regTitle').html();