Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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
Jquery 使用其他字段值设置表的选中字段值_Jquery_Apex - Fatal编程技术网

Jquery 使用其他字段值设置表的选中字段值

Jquery 使用其他字段值设置表的选中字段值,jquery,apex,Jquery,Apex,我在jQuery中遇到了一些麻烦。 我在一个有3列的表中有一些行(复选框、名称、金额) 我在桌子上方还有一个字段。 在这里,我想将此字段的值复制到选中复选框的金额字段中。 在屏幕截图中,我想把黄色的值放到表的checked字段中 为销售分配配额: 就像我说的,我不知道apex,但这里有一个大概的想法: 一旦您能够获得选中的复选框,您需要在每个复选框和其后续输入之间建立关系:因此您需要为每个输入提供一个唯一的id:如下所示: <input type="checkbox" data-inpu

我在jQuery中遇到了一些麻烦。 我在一个有3列的表中有一些行(复选框、名称、金额) 我在桌子上方还有一个字段。 在这里,我想将此字段的值复制到选中复选框的金额字段中。 在屏幕截图中,我想把黄色的值放到表的checked字段中

为销售分配配额:

就像我说的,我不知道apex,但这里有一个大概的想法:

一旦您能够获得选中的复选框,您需要在每个复选框和其后续输入之间建立关系:因此您需要为每个输入提供一个唯一的id:如下所示:

<input type="checkbox" data-inputid="val1">
<input type="text" id="val1"> 
<input type="checkbox" data-inputid="val2">
<input type="text" id="val2"> 
因此,即使您获得了选中的复选框,您也在选中的元素上循环,但随后您使用
id=“test”
选择了所有字段,并且由于您的所有输入都具有id='test',因此值被复制到任何地方都是正常的


希望获得此帮助:)

我们需要html代码我已经更新了我的帖子:)您确定
$(“输入[type=checkbox][checked]”
正在返回所选的复选框吗?我想它一定是
$(“input[type=checkbox]:checked”)
首先检查我是否更改了它,它是相同的,值复制到表的所有字段中,而不是选中的字段中。我不知道附录:(那么,您可以发布生成的HTML代码吗?感谢您的解释,我尝试了很多方法来回答您的问题,但表中的值没有改变。我放置了一些console.log(),inputid的返回值为“val1”,valuetocopy的返回值为“我在字段中输入的值”。因此,您得到的是ID和值,但输入值没有更改?如果是,则可能意味着您没有为输入字段提供正确的ID:每个复选框的data inputid属性中的值必须等于相关输入字段的ID属性。如果您可以加入生成字段的printscreen,则会有所帮助表格的html代码正如您所看到的,输入字段的id是j_id0:formid…val1,这就是JQuery找不到它的原因。如果无法将其强制为val1,则将行
$('#'+inputid).val(valuetocopy);
更改为
$([input[type='text'][id$=inputid]]).val(valuetocopy)
将选择id以inputid value结尾的任何文本输入。也不会发生任何情况,如果我将
$(“input[type='text'][id$=inputid]”)更改为.val(valuetocopy)
$(“input[type='text'][id$=val1]”。val(valuetocopy)
则所有表都会更改,这是正常的。
<input type="checkbox" data-inputid="val1">
<input type="text" id="val1"> 
<input type="checkbox" data-inputid="val2">
<input type="text" id="val2"> 
function copyQuotaAmount()
    {
        $("input[type=checkbox]:checked").each(function(){
            // $(this) refers to the current checked box in loop
            var inputid = $(this).data('inputid');
            var valuetocopy = $('#ValueToCopy').val();
            // if you can force the id of the input field to a specific value then use this
            $('#' + inputid).val(valuetocopy);
            // else if you can't force the value (then based on your html output), you must use this
            $("input[type='text'][id$='" + inputid + "']").val(valuetocopy)

        });
    }