如何在特定元素之后动态生成元素

How to generate a element dynamically after a specific element

本文关键字:元素 之后 动态      更新时间:2023-09-26

我正在使用javascript动态生成一个文本字段。问题是新的文本字段是在文件类型之前生成的。我想在文件类型之后并在新行中生成它。我已经共享了代码。

html

<input type="text" name="textf"/>

http://jsfiddle.net/QxPbJ/2/

希望你了解

提前感谢

您没有使用表,但添加了tr和td。首先将表放在字段后面,然后将tr添加到

尝试此链接单击此处

Html

<input type="radio" name="choices"/>
<input style="margin-bottom:20px;"id="option1" class="ABC" name="option1"type="text"/>
<input type="file" name="op" id="op"/>
<div id="appendBefore"></div>

Js

$(function () {
  count = 2;
  var createNewField = function() {
  var $node = $('<tr><td></td><td><input type="radio" name="choices" name="o" id="o"     style="float:left"/><div class="XYZ" style="float:left"><input style="margin-bottom:20px; " class="ABC" type="text" name="option" id="option" placeholder="add option '+count+'"/>   </div>&emsp;<input type="file"/></td></tr>');
  if(count < 6){
    $node.find("input.ABC").one('click', createNewField);
    $('#appendBefore').before($node);
    count = count+1;
  }
};
$('input.ABC').one('click', createNewField);
});

你的意思是这样的吗?

$(function () {
    count = 2;
    var createNewField = function () {
        var node = $('<tr><td></td><td><input type="radio" name="choices" name="o" id="o" style="float:left"/><div class="XYZ" style="float:left"><input style="margin-bottom:20px; " class="ABC" type="text" name="option" id="option" placeholder="add option' + count + '"/></div>&emsp;<input type="file"/></td></tr>');
        if (count < 6) {
            $('input').last().after(node);
            count++;
            node.click(function () {
                createNewField();
            });
        };
    };
    $('input.ABC').click(function () {
        createNewField();
    });
});