我正在尝试使用jquery将html中的id设置为位于对象内部属性内的字符串集。但是由于某种原因,当我运行程序时,jQuery脚本不起作用。我尝试在document.ready中设置html DOM代码,还尝试在激活其他事件但没有任何更改的情况下运行的函数中运行代码。帮我解决这个问题。
$(document).ready(function() {
var testObj = {
exampleText = "Hello world"
};
$("#test").html(testObj.exampleText);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p id="test"></p>
答案 0 :(得分:0)
您遇到语法错误。 使用var testObj = {exampleText:“ Hello world”};代替。