【问题标题】:How to data-bind HTML attribute with jQuery如何使用 jQuery 对 HTML 属性进行数据绑定
【发布时间】:2020-03-12 16:26:47
【问题描述】:

我需要用jQuery绑定数据属性

<div class="easypiechart" id="easypiechart-blue" data-percent="name" ><span class="percent">{{name}}%</span></div>

我需要将“名称”值与 jQuery 绑定。 我怎么能在javascript中做到这一点。 请帮忙。

我需要在 JS 中用 Jquery 设置“名称”值。

【问题讨论】:

    标签: javascript jquery html data-binding attributes


    【解决方案1】:

    您的问题含糊不清,但假设您无法控制加价。

    <div class="easypiechart" id="easypiechart-blue" data-percent="name" >
        <span class="percent">
            {{name}}%
        </span>
    </div>
    

    JS

    var el = document.getElementById(“easypiechart-blue”)
    
    el.data.percent = your val here;
    

    【讨论】:

    • 它不工作。我想把 [ data-percent="name" ] 变成 [ data-percent="some value"]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-12
    • 2012-04-08
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    相关资源
    最近更新 更多