Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.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/79.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
Javascript Can';t使用jquery更新隐藏的复选框名称属性_Javascript_Jquery_Checkbox - Fatal编程技术网

Javascript Can';t使用jquery更新隐藏的复选框名称属性

Javascript Can';t使用jquery更新隐藏的复选框名称属性,javascript,jquery,checkbox,Javascript,Jquery,Checkbox,在类名为funding\u status\u hidden的克隆隐藏复选框输入中,更新funding\u status[0]的name属性时遇到问题。我可以用下面的js脚本更新带有类状态的正常输入。它还按照预期更新了一系列其他复选框字段——努力使最后一个字段发生更改 $(document).ready(function(){ var template = $('#products .product:first').clone(); var productsCount = $('.product'

在类名为funding\u status\u hidden的克隆隐藏复选框输入中,更新funding\u status[0]的name属性时遇到问题。我可以用下面的js脚本更新带有类状态的正常输入。它还按照预期更新了一系列其他复选框字段——努力使最后一个字段发生更改

$(document).ready(function(){
var template = $('#products .product:first').clone();
var productsCount = $('.product').length-1; 

window.addProduct = function(){
    productsCount++;
    var product = template.clone().find(':input, .days').val('0').prop('checked', false).each(function(){

        var newId = this.id.substring(0, this.id.length-1) + productsCount;

        $(this).next(':input, label').attr('for', newId); // update label for
        $(this).next(".funding_status").attr('name', function() { return $(this).attr("name").substring(0, this.id.length-2) + "["+productsCount+"]" });
        $(this).next(".funding_status_hidden").attr('name', function() { return $(this).attr("name").substring(0, this.id.length-2) + "["+productsCount+"]" });


        this.id = newId; // update id and name (assume the same)



        $(this).find(".cloned_checkbox_hidden").attr("name", function() { return $(this).attr("name").substring(0, this.id.length-9) + "["+productsCount+"]" });
        $(this).find(".cloned_checkbox").attr("name", function() { return $(this).val('1').attr("name").substring(0, this.id.length-2) + "["+productsCount+"]" });




    }).end()
    .attr('id', 'product' + productsCount)
    .appendTo('#products');

}
$('.add').click(addProduct);
$("a#rp").click(function () {
    productsCount--;
if ($(".product").length != 1) {
$(".product:last").remove();
}
event.preventDefault();
});
});
克隆Div的HTML(稍微缩减一点以显示我正在尝试更新的资金部分)


基金
-
三,
HC
资金数额
资金状况
经核准的
使用

更改名称

并且不要在名称中使用[0]

像这样使用数据名

<input data-name="array[0]" >

Id是在.clone过程中生成的,Id后面附加了一个数字,因此在本例中,要获取Id有点困难,类是否可能?使用classname并使用classname获取相对输入我可以执行类似
var t=document.getElementById(“产品”+productsCount”)
的操作来选择克隆的数据容器吗?是(“产品”)“+productsCount)我最终使用了
var t=document.getElementById(“资金状况”\u隐藏”+productsCount).name=“资金状况”+”[“+productsCount+”]”以获取我需要的内容。谢谢你让我走上正轨侯赛因!你能创建一个工作的演示/片段或者一个可以使用的文档吗?
document.getElementById("input-id").name ="new name";
<input data-name="array[0]" >
var t = document.getElementById("cloned-data-container");

t.querySelector(".your-spacial-input-classname").name = "custom value";