我怎样才能做到以下几点:

document.all.regTitle.innerHTML = 'Hello World';

使用jQuery哪里regTitle是我的div id?


当前回答

html()函数可以接受html字符串,并有效地修改. innerhtml属性。

$('#regTitle').html('Hello World');

然而,text()函数将改变指定元素的(text)值,但保持html结构。

$('#regTitle').text('Hello world'); 

其他回答

$("#regTitle")[0].innerHTML = 'Hello World';

你可以使用HTML或jquery的文本函数来实现它

$("#regTitle").html("hello world");

OR

$("#regTitle").text("hello world");
$("#regTitle").html("Hello World");

html()函数可以接受html字符串,并有效地修改. innerhtml属性。

$('#regTitle').html('Hello World');

然而,text()函数将改变指定元素的(text)值,但保持html结构。

$('#regTitle').text('Hello world'); 

例子 $(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 >