点击时无法动态更改div的内容

时间:2020-02-03 19:45:53

标签: jquery

我想在content内添加字符串div,但是我的代码无法正常工作。我在做什么错了?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    function getContentOfAreas() {
    console.log("will add content");
    $('#preview').InnerHtml = "content";
    }
</script>
<div id="preview" style="height:100px;border:1px solid black"></div>
<button type="button" onclick="getContentOfAreas()">click me to see content</button>

1 个答案:

答案 0 :(得分:0)

innerHTML是普通JavaScript,因为您已经在使用jQuery,所以只能使用.html()方法。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    function getContentOfAreas() {
      console.log("will add content");
      $('#preview').html("content");
    }
</script>
<div id="preview" style="height:100px;border:1px solid black"></div>
<button type="button" onclick="getContentOfAreas()">click me to see content</button>

相关问题