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

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

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


当前回答

答:

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

解释:

$相当于jQuery。它们都表示jQuery库中的相同对象。括号内的“#regTitle”被称为选择器,jQuery库使用它来确定您想要将代码应用到html DOM(文档对象模型)的哪个元素。regTitle前面的#告诉jQuery, regTitle是DOM中元素的id。

从那里,点表示法被用来调用html函数,它用你放在括号之间的任何参数替换内部html,在这种情况下是'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 >

var abc = document.getElementById("regTitle");
abc.innerHTML = "Hello World";

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

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

OR

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

以下是你的答案:

//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();
$("#regTitle").html("Hello World");