Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jquery生成的总和仅显示在文本框值中,而不保存在文本框值中_Php_Jquery_Wordpress - Fatal编程技术网

Php jquery生成的总和仅显示在文本框值中,而不保存在文本框值中

Php jquery生成的总和仅显示在文本框值中,而不保存在文本框值中,php,jquery,wordpress,Php,Jquery,Wordpress,顺便说一句,我正在使用wordpress插件kboard,我正在尝试包含这个函数,其中用户在3个文本框中插入的值将使用jquery添加,下面是我的代码: $(".add").keyup(function(){ var sum = 0; $(".add").each(function() { sum += +this.value; }); $(".total").val(sum);}); 我的问题是,里面的属性值没有改变,它只显示总和。如果我必须使用ajax,我的代

顺便说一句,我正在使用wordpress插件kboard,我正在尝试包含这个函数,其中用户在3个文本框中插入的值将使用jquery添加,下面是我的代码:

$(".add").keyup(function(){
var sum = 0;    
$(".add").each(function() {      
    sum += +this.value;
});

$(".total").val(sum);});
我的问题是,里面的属性值没有改变,它只显示总和。如果我必须使用ajax,我的代码应该是什么样子

var sum = 0;   
  $(".add").keyup(function(){        
        sum += +this.value; 
   });
$(".total").val(sum);

在keyup函数外初始化'sum'变量。

好的,我看到了我的错误,我重新阅读了我的代码,我觉得自己真的很愚蠢,ohmy。事实证明,这是因为我在输入框中输入disable=true,这就是为什么当我应该使用readonly oh my gahd时,它没有保存。谢谢你的回答。这么愚蠢的错误-__-

为什么删除此.value之前的+?OP将其转换为一个数字,因此它不会被连接为字符串。感谢您的回复,我使用的是一个php插件,因此这些值将在提交时保存在数据库中。。。jquery正在运行,但是里面的值.total没有保存,你有什么建议吗?哪里没有保存.total?啊,对不起!!这是因为我将disable=true放在我的文本框中,因为我认为用户不应该编辑该文本框,但后来我将其更改为“只读”,并将其保存。欧姆加。对不起!!T^T感谢您的回复,但我正在使用一个插件,其中的值使用php保存到数据库中。jquery正在工作,但是值sum没有被保存,您有什么建议我应该使用什么来保存jquery生成的sum?
// save (cache) this element in a variable for later use to save computation
var $values = $(".add");

$values.keyup(function() {
    // reset the sum
    var sum = 0;    
    $values.each(function() {      
        sum += +this.value;
    });

    // assuming total is an input, you can then set the value
    $(".total").val(sum);

    // if we're literally setting an attribute named "value", then
    $(".total").attr("value", sum);

    // if total is not an input and we're just updating its contents
    $(".total").text(sum);
});