Javascript 使用+;jQuery提供的1个ID

Javascript 使用+;jQuery提供的1个ID,javascript,jquery,html,Javascript,Jquery,Html,我用自定义样式为添加新输入创建代码,但我需要在单击时更改id号和“for”标记值 我需要添加id=“input-2”和for=“input-2” 在单击中,我需要添加id=“input-3”和for=“input-3”的新html 此代码: var maxSocial=10, socialWrapper=$(“#socialWrapper”), addSocial=$(“#add social”), 社会指数=1; $(添加社交)。单击(功能(e){ e、 预防默认值(); if(社交X

我用自定义样式为添加新输入创建代码,但我需要在单击时更改id号和“for”标记值

我需要添加id=“input-2”和for=“input-2” 在单击中,我需要添加id=“input-3”和for=“input-3”的新html

此代码:

var maxSocial=10,
socialWrapper=$(“#socialWrapper”),
addSocial=$(“#add social”),
社会指数=1;
$(添加社交)。单击(功能(e){
e、 预防默认值();
if(社交X

社会联系

您希望根据公共字符串“input-”创建id并附加socialX

$(addSocial).click(function (e) {
    e.preventDefault();
    if (socialX < maxSocial) {
        socialX++;
        var thisId = "input-" + socialX;
        $(socialWrapper).append('<div class="inputbox"><div class= "inputbox-content"><input id="' + thisId + '" type="text" required /><label for="' + thisId + '">Social Link</label><span class="underline"></span></div></div>');
    }
});
$(添加社交)。单击(功能(e){
e、 预防默认值();
if(社交X

工作JSIDLE:

谢谢,伙计,这是工作,但我把它改为:var thisId=socialX;