【问题标题】:Get data info in HTML field using JQuery使用 JQuery 获取 HTML 字段中的数据信息
【发布时间】:2021-07-24 15:06:43
【问题描述】:

我有一个使用数据属性计算的自动字段,但我不能使用该字段,所以我想使用 Jquery 复制该功能,我想要一个按钮来使用 Jquery 函数执行此操作并填充一个文本字段。

最初我有这个:

<input type="radio" name="radio-1" value="female" id="forminator-field-radio-1-2-608c8cfc0bc56" data-calculation="0">

还有几个像以前一样, 然后自动填充的字段有:

<input type="number" name="calculation-1" value="" id="calculation-1-field" class="test-calculation" data-formula="({radio-1} * (10*{number-2} + 6.25*{number-3}) * {number-2})" data-required="" data-precision="0" data-is-hidden="" disabled="disabled">

但是,我希望带有 JQuery 的按钮执行类似的操作,但它不起作用:

<script>
$(document).on('click','#calculatecal',function(){
    $("#caloryid h3").html({radio-1});
});

</script>

脚本没有得到radio-1,我该如何查询数据?是数据计算还是如何模拟数据公式?

谢谢,

【问题讨论】:

    标签: javascript jquery custom-data-attribute


    【解决方案1】:

    嗨,我不明白,但也许你正在寻找这个!?!

    <script>
    $(document).on('click','#calculatecal',function(){
        $("#caloryid h3").html({radio-1} * (10*{number-2} + 6.25*{number-3});
    });
    
    </script>
    

    【讨论】:

    • 嗨,感谢您的回复,但是,在“数据公式”内部,它了解什么是无线电 1,但在外部不了解,这就是为什么我想知道是否有任何命令我可以使用“radio 1”,而无需为每个元素添加一个额外的类,并使用 jquery 找到它,如 $(id)
    • 你是否正在寻找 $('td[name="radio-1"]') // Matches exactly 'radio-1' $('td[name^="radio"]' ) // Matches those that begin with 'radio' $('td[name$="-1"]' ) // Matches those that end with '-1' `$('td[name*="radio"]' ) // 匹配那些包含 'radio' 这里是 @ 987654321@
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    相关资源
    最近更新 更多