Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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_Ajax_Textbox - Fatal编程技术网

Php jquery更新多个字段

Php jquery更新多个字段,php,jquery,ajax,textbox,Php,Jquery,Ajax,Textbox,代码中有什么错误吗它实际上并没有更新所有的textinput,只是在单击保存后更新第一个输入id=1 HTML标记: <input type="text" id="1"> <input type="text" id="2"> <input type="text" id="3"> <input type="text" id="4"> <input type="text" id="5"> <input type="text" id="

代码中有什么错误吗它实际上并没有更新所有的textinput,只是在单击保存后更新第一个输入id=1

HTML标记:

<input type="text" id="1">
<input type="text" id="2">
<input type="text" id="3">
<input type="text" id="4">
<input type="text" id="5">
<input type="text" id="6">
PHP:

$counter=$\u POST['count'];
$value=$\u POST['text\u value'];
$id=$_POST['id'];
$i=0;
如果($counter!=0):
而($iquery(“更新关联设置d_百分比='$value'其中id_关联='$id'));
结束时;
$data[“message”]=“附属公司百分比值已更改!”;
$data['success']=true;
endif;
使用

操作每个捕获的元素。

使用


要操作每个捕获的元素。

如Stefan的回答中所述,您需要使用某种循环来迭代您获得的每个输入元素。 原因是tha
.attr()
方法返回要调用它的元素集中第一个元素的属性。 因此,当你执行

var af_value = $(this).find("input[type=text]").attr("value");
var af_id = $(this).find("input[type=text]").attr("id");

您只检索与选择器匹配的第一个输入元素的id和值;在您的示例中,它是id=1的输入元素。

正如Stefan的回答中所提到的,您需要使用某种循环来迭代已获得的每个输入元素。 原因是tha
.attr()
方法返回要调用它的元素集中第一个元素的属性。 因此,当你执行

var af_value = $(this).find("input[type=text]").attr("value");
var af_id = $(this).find("input[type=text]").attr("id");
您只检索与选择器匹配的第一个输入元素的id和值;在您的情况下,它是id=1的元素。

您在表单上使用
。each()
,但您需要在输入上使用它:

$('#save_affiliate').live('click', function() {
    var $inputs = $('#affiliate_form').find("input[type=text]");
    $inputs.each(function(i) {
        var counter = $inputs.length;
        var af_value = $(this).attr("value");
        var af_id = $(this).attr("id");
        $.post("include/setting.php?affiliate", {
            id: af_id,
            text_value: af_value,
            count: counter
        }, function(data) {
            if (data.success) {
                $('.err').html(data.message).fadeIn('slow');
            } else {
                $('.err').html(data.message).fadeIn('slow');
            }
        }, "json");
    });
    return false;
});
您也不需要检查
计数器>0
,因为如果没有任何
输入[type=text]
,函数将不会运行。如果您想将count键作为输入的索引,则使用传递给each函数的
i
参数。

您使用的是
.each()
,但您需要在输入时使用它:

$('#save_affiliate').live('click', function() {
    var $inputs = $('#affiliate_form').find("input[type=text]");
    $inputs.each(function(i) {
        var counter = $inputs.length;
        var af_value = $(this).attr("value");
        var af_id = $(this).attr("id");
        $.post("include/setting.php?affiliate", {
            id: af_id,
            text_value: af_value,
            count: counter
        }, function(data) {
            if (data.success) {
                $('.err').html(data.message).fadeIn('slow');
            } else {
                $('.err').html(data.message).fadeIn('slow');
            }
        }, "json");
    });
    return false;
});
您也不需要检查
计数器>0
,因为如果没有任何
输入[type=text]
,函数将不会运行。如果您想将计数键作为输入的索引,则使用传递给每个函数的
i
参数

$('#save_affiliate').live('click', function() {
    var $inputs = $('#affiliate_form').find("input[type=text]");
    $inputs.each(function(i) {
        var counter = $inputs.length;
        var af_value = $(this).attr("value");
        var af_id = $(this).attr("id");
        $.post("include/setting.php?affiliate", {
            id: af_id,
            text_value: af_value,
            count: counter
        }, function(data) {
            if (data.success) {
                $('.err').html(data.message).fadeIn('slow');
            } else {
                $('.err').html(data.message).fadeIn('slow');
            }
        }, "json");
    });
    return false;
});