Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 生成ID';用于Jquery中的文本和日历控件的_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 生成ID';用于Jquery中的文本和日历控件的

Javascript 生成ID';用于Jquery中的文本和日历控件的,javascript,jquery,html,css,Javascript,Jquery,Html,Css,每当我点击时,我想为输入类型文本生成Id。添加类。当前,每当我单击.add类时,它都会为每个输入控件生成具有相同名称的id。因此,在添加数据时,它无法正常工作 那么,每当我点击。add类时,我应该如何为每个文本生成ID呢。请建议 这就是我们要做的 $('.add')。在('click',function()上{ var$tr=$(this.closest('tr'); var$tr2=$tr.clone(true,true); $tr2.find(“.vendorName”).childre

每当我点击
时,我想为输入类型
文本
生成
Id
。添加
类。当前,每当我单击
.add
类时,它都会为每个输入控件生成具有相同名称的id。因此,在添加数据时,它无法正常工作

那么,每当我点击
。add
类时,我应该如何为每个文本生成ID呢。请建议

这就是我们要做的

$('.add')。在('click',function()上{
var$tr=$(this.closest('tr');
var$tr2=$tr.clone(true,true);
$tr2.find(“.vendorName”).children('label').remove();
$tr2.find(“.vendorFromDate”).children('label').remove();
$tr2.find(“.vendorToDate”).children('label').remove();
$tr2.find(“.vendorName”).children().unwrap();
$tr2.find(“.vendorFromDate”).children().unwrap();
$tr2.find(“.vendorToDate”).children().unwrap();
$tr2.插入符($tr);
});

SP供应商名称
从日期开始
迄今为止
(最多5家供应商)

好吧,您可以根据您拥有的物品数量生成ID

你会有类似

            $(".add").on("click", function(){
            var numBlocks = $('.vendorDaterow').length; 
/*gets number of elements with this class in DOM*/

            var formStructure = "";
            formStructure = "<div id='formRow"+numBlocks+"' class='vendorDaterow'>";
            formStructure = "<div class='vendorName' id='dvVendorNameData"+numBlocks+"'>";
            formStructure = "<label>SP Vender Name</label><span><input type='text' name='nmVendorData' id='txtVendorName"+numBlocks+"' />";
            /*continue for whole structure*/

            $("#formRow"+(numBlocks-1)).parent().append(formStructure);
     /*finds last existing #formRow, gets his parent node and append your new node into it. Also you can do your other logic based on id, like hiding the add button or something.*/


        });
$(.add”)。在(“单击”,函数(){
变量numBlocks=$('.vendorDaterow').length;
/*获取DOM中此类的元素数*/
var formStructure=“”;
formStructure=“”;
formStructure=“”;
formStructure=“SP供应商名称”;
/*继续整个结构*/
$(“#formRow”+(numBlocks-1)).parent().append(formStructure);
/*查找最后一个存在的#formRow,获取其父节点并将新节点附加到其中。此外,您还可以根据id执行其他逻辑,例如隐藏“添加”按钮或其他操作*/
});
请注意,计数ID从0开始(您什么都没有,长度是0。因此第一个添加的节点将是#formRow0。

检查此项

(函数(){
var toAddCloneCount=2;
$('.add')。在('click',function()上{
var$tr=$(this.closest('tr');
var$tr2=$tr.clone(true,true);
$tr2.find(“.vendorName”).children('label').remove();
$tr2.find(“.add”).children().remove();
$tr2.find(“.vendorFromDate”).children('label').remove();
$tr2.find(“.vendorToDate”).children('label').remove();
$tr2.find('txtVendorName').prop('id','txtVendorName'+toAddCloneCount);
$tr2.find(“#spFromDate1”).prop('id','spFromDate'+toAddCloneCount);
$tr2.find('#spToDate1').prop('id','spToDate'+toAddCloneCount++);
$tr2.插入符($tr);
});
})();
.vendorName、.vendorFromDate、.vendorToDate{
宽度:33%;浮动:左;}

SP供应商名称@*Shri Kamalkanth公司。*@
从日期开始
迄今为止
(最多5家供应商)

@Satpal:很抱歉,可能是这样。但我想要的是生成id的想法,而不是用户要求的me@Satpal当前位置我期待他提供更多建议,但他没有回复。因此,我发布了这篇文章,开始我想生成ID'sHope this helps@AshishKumar:我想这与聊天中的内容不同。我现在回来了