如何使用对象问题修复jQuery DOM

问题描述 投票:-1回答:1

我正在尝试使用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>
javascript jquery html dom
1个回答
0
投票

您有语法错误。使用var testObj = {exampleText:“ Hello world”};代替。

© www.soinside.com 2019 - 2024. All rights reserved.