小编Mat*_*att的帖子

为html表单创建输入字段...但也为它添加"标签"?

我有一个HTML表单.单击该按钮时,javascript函数会添加一个新字段.我正在尝试让该功能也为该字段添加"标签".

我已经尝试过使用document.createElement("LABEL"),但这不允许我更改innerHtml(或者我可能做错了..),也没有添加结束

这是我的代码.谢谢!var instance = 2;

        function newTextBox(element)
        {       
            instance++; 
            // Create new input field
            var newInput = document.createElement("INPUT");
            newInput.id = "text" + instance;
            newInput.name = "text" + instance;
            newInput.type = "text";
            instance++; 

            document.body.insertBefore(document.createElement("BR"), element);
            document.body.insertBefore(newInput, element);

        }
    </script>
</head>


<body>
    <LABEL for="text1">First name: </LABEL>
    <input id="text1" type="text" name="text1">
    <LABEL for="text2">Last name: </LABEL>
    <input id="text2" type="text" name="text2">



    <input type="button" id="btnAdd" value="New text box" onclick="newTextBox(this);" />
</body>
Run Code Online (Sandbox Code Playgroud)

html javascript forms label

8
推荐指数
2
解决办法
3万
查看次数

jquery'remove class' - 尝试删除具有特定类的所有元素

所以我有2个div,每个都有n个元素.2个div中有n对元素.每对使用相同的"类".

是否有可能一次删除一对特定的对?我目前正在使用以下代码:

    function leaveGroup(id)
    {

        var e = document.getElementById(id);
        var f = $(e).parentNode;

        // Remove everything with the same class name of the parent
        $('body').removeClass($(f).className);

    }
Run Code Online (Sandbox Code Playgroud)

该功能不起作用,我是否错误地使用了类名?谢谢!

jquery removeclass

2
推荐指数
1
解决办法
5299
查看次数

标签 统计

forms ×1

html ×1

javascript ×1

jquery ×1

label ×1

removeclass ×1