简体   繁体   English

jQuery Keyup脚本更新输入值不起作用

[英]Jquery Keyup script to update input value not working

I have a script that adds up data-attributes from checkboxes, I modified the script to be able to allow users to manually add their own entries into a text input that the keyup function copies into the data-cost="" and debt="" attributes, which a plugin recalculates the total into the blue div box on the right side in this Fiddle . 我有一个脚本,可以将复选框中的数据属性加起来,我对该脚本进行了修改,以使用户可以将自己的条目手动添加到text input ,从而将keyup函数复制到data-cost=""debt=""属性,该插件会将总数重新计算到该小提琴右侧的蓝色div框中。 This functionality works, as you can see in the fiddle 正如您在小提琴中看到的那样,此功能有效

But I also want data that is copied into the data-attributes to also be copied into the value="" . 但我也希望复制到data-attributes中的数据也复制到value="" The plugin uses the value to display it in the yellow summary box on the right, but every time I modify the keyup script, the calculation stops working and the value does not show up in the summary. 插件使用该值将其显示在右侧的黄色摘要框中,但是每次我修改keyup脚本时,计算都会停止工作,并且该值不会显示在摘要中。

Here is the Fiddle 这是小提琴

This is the keyup script: 这是键盘脚本:

function calculateTotalFor(){
    $('#jquery-order-form').data('jprice').onChange();
}
$(function () {
    $(document).on('keyup blur paste', '.balance', function() {  //Changed here
        var $self = $(this),
        $checkbox = $self.closest('li').find('input:checkbox');
        setTimeout(function() {
            var str = $self.val();
            $checkbox.data('cost',str.replace(/^\$/, ''));
            $checkbox.data('debt',str.replace(/^\$/, ''));
            calculateTotalFor();
        }, 0)
    })    
});

I added $checkbox.val(str.replace(/^\\$/, '')); 我添加了$checkbox.val(str.replace(/^\\$/, '')); before calculateTotalFor(); calculateTotalFor();之前calculateTotalFor(); and it seems to work. 而且似乎可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM