【问题标题】:Codeigniter create new textfield on button/link click [closed]Codeigniter 在按钮/链接单击上创建新文本字段 [关闭]
【发布时间】:2014-11-15 15:49:24
【问题描述】:

我正在尝试为我的网站制作申请表,我需要一个可以在点击时添加新输入字段的按钮,但我不知道如何解决这个问题。

想象一下:

[按钮]

一个按钮,当您单击它时,它将创建一个新的文本字段, 当你多次点击它时,它会看起来像下面的东西。

[文本字段]

[文本字段]

[文本字段]

[文本字段]

【问题讨论】:

  • 我什么都没试过......我真的不知道如何实现这一目标。我对 codeigniter 和 php 有点陌生。

标签: javascript php mysql codeigniter


【解决方案1】:

你可以试试这个

<form action="test.php" method="post" id="form">
<input type="text" name="id">
<input type="submit">
</form>
<button id="add">Add</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
var i = 1;
$('#add').click(function(){
    var newEl = '<input type="text" placeholder="Text Field '+(i+1)+'" name="'+(i++)+'"><br />';
    $('#form').prepend(newEl);
});
</script>

<form action="test.php" method="post" id="form">
    <input type="text" name="id">
    <input type="submit">
</form>
<button id="add">Add</button>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
    var i = 1;
    $('#add').click(function(){
        var newEl = '<input type="text" placeholder="Text Field '+(i+1)+'" name="'+(i++)+'"><br />';
        $('#form').prepend(newEl);
    });
</script>

【讨论】:

  • 哦,非常感谢!答案,但我可以问我如何设置它,以便新字段出现在文本字段的底部而不是顶部?
  • 使用append() 而不是prepend()
  • 啊,这就是 prepend 的作用。再次感谢您的回答!。如果可以的话,我会支持你的回答,但我没有足够的声誉来做这件事。
  • @AccullusHartlezZeltania 不客气!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-02
  • 1970-01-01
  • 2016-11-03
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
相关资源
最近更新 更多