【问题标题】:Conversion of html to object failed using JQuery使用 JQuery 将 html 转换为对象失败
【发布时间】:2022-07-21 20:44:52
【问题描述】:
<div class = "containing mt-3">
    <div class = "card p-3">
        <span id = 'car-title'>상품명</span>
        가격
    </div>
</div>    

<script>
    var car = {name: 'Ferrari', price: 50000}
    $('#car-title').html = car.name;
   </script>

我想将 상품명 更改为 Ferrari,但没有更改。 如果我使用此代码,

document.querySelector('.car-title').innerHTML = car2.name;

它工作正常。 我认为 JQuery 是问题的原因,但我不知道使用 JQuery 的原因和解决方案! (我已经安装了 JQuery。)

【问题讨论】:

  • “我认为 JQuery 是问题的原因” - 好吧,你没有正确使用它的部分是...... html 是一个 方法 i>,不是属性。 api.jquery.com/html

标签: javascript jquery object variables


【解决方案1】:

$('.selector').html() 是一个函数。 https://api.jquery.com/html/

$('select').html(?)代替$('select').html = ?

【讨论】:

    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    相关资源
    最近更新 更多