Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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 - Fatal编程技术网

使用Jquery为不同的多个文本框设置不同的多个值

使用Jquery为不同的多个文本框设置不同的多个值,jquery,Jquery,我正在创建一个脚本,管理员可以添加所有国内地区的费用,也可以添加国际地区的费用。情况是:- 管理员点击添加费用按钮。在那里,他可以增加费用、成本和交货天数。现在我想为所有具有name=delivery\u charge[][charge]的文本框设置charge的值,为所有具有name=delivery\u charge[][cost]的文本框设置delivery\u days的值,并为所有具有name=delivery\u charge[][days]的文本框设置的值 我所做的是 functi

我正在创建一个脚本,管理员可以添加所有国内地区的费用,也可以添加国际地区的费用。情况是:-

管理员点击添加费用按钮。在那里,他可以增加费用、成本和交货天数。现在我想为所有具有
name=delivery\u charge[][charge]
的文本框设置
charge
的值,为所有具有
name=delivery\u charge[][cost]
的文本框设置
delivery\u days
的值,并为所有具有
name=delivery\u charge[][days]的文本框设置
的值

我所做的是

function addCharges(type){
var cost = parseFloat($('#modal-cost').val());
var charge = parseFloat($('#modal-charge-box').val());
var days = parseInt($('#modal-days').val());

if(isNaN(cost)){
    cost = 0;
}

if(isNaN(charge)){
    charge = 0;
}

if(isNaN(days)){
    days = 0;
}

if(type == 'domestic'){
    $('.domesticZones :checkbox').prop("checked", true);
    $('.domesticZones input').prop("readonly", false);

   //What code should i put here so that all text box with name delivery_charge[][cost] have value of cost and same for variables charge and days.


}else if(type == 'international'){
    $('.internationalZones :checkbox').prop("checked", true);
}
}
使用以下命令:

// find name with [cost] at the end of name
$('input[name$="[cost]"]').val(cost);
// same goes to the others
更新的注释应该可以做到这一点,您也可以使用regex尝试此解决方案,但与上面的代码相比,这需要相当多的新行:

$('input[name$="[cost]"]').filter(function(){
  // find the attribute name start with `delivery_charge` 
  // name and not followed by `_`
  var regex = /delivery_charge(?!\_)/;
  if ( regex.test( $(this).attr('name') ) ) return this;              
}).val(cost);

阅读此内容并查看此内容。

您能否发布由php脚本生成的相关HTML代码它可以工作,但它也会更改具有
name=delivery\u charge\u international[][days]
*
[cost]
天数
的文本框的值。使用此
$('.domesticZones输入[name$=”[cost]')。val(cost);
。很高兴听到这个消息