【问题标题】:How to Change the Contents ("value") of a Custom Attribute如何更改自定义属性的内容(“值”)
【发布时间】:2015-06-10 16:51:55
【问题描述】:

我有以下 HTML5 自定义属性:

<input ... class="my-input" data-counted="N">

如何在 jquery 中更改它的值(从“N”到“Y”)?

这是我所拥有的,但它不起作用:

$(document).on('change', '.my_input', function() {
    $(this).attr('data-counted').val('Y');
});

【问题讨论】:

    标签: jquery html custom-attributes


    【解决方案1】:

    你可以使用

    $(this).attr('data-counted','Y');
    

    $(this).data('counted','Y');
    

    【讨论】:

    • 太棒了...做到了。我稍后会接受这个作为答案——服务不会让我再等 10 分钟
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-11
    • 2014-06-08
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多