我想在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>
答案 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>