在文本区域中写入#Q#时打开输入
我有文本区域。现在,我想这样做,一旦你写“#q + number#”(例如#q1#),它将创建新的输入字段。 例如,如果您写:“你好,我的名字是#q1#,我最喜欢的食物是#q2#”。它将打开两个输入字段。
当您删除其中一个 #q + number# 时,它将删除用于 #q# 的相同字段,
例如:如果您写“你好,我的名字是 #q1#,我最喜欢的食物是 #q2#,输入字段看起来像这样:
<input type="text" q="1" />
<input type="text" q="2" />
接下来我删除 #q1# 它应该看起来像这样:
并且不要删除 q="2" 输入的值。
我怎样才能在 jQuery/JavaScript 中做到这一点?
I have textarea. Now, I want to do that once you write "#q + number#" ( e.g. #q1# ), it will create new input field.
For example if you write: "Hello my name is #q1# and my favorite food is #q2#". It will open two input fields.
And when you delete one of those #q + number#, it will delete the same field that was intended to the #q#
For example: if you write "Hello my name is #q1# and my favorite food is #q2#, and the input fields look like that:
<input type="text" q="1" />
<input type="text" q="2" />
and next that I delete the #q1# it supposed to look like that:
and don't delete the value of q="2" input.
How can I do that in jQuery/JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看这个快速小提琴 http://jsfiddle.net/NgxvP/1/
Take a look at this quick fiddle http://jsfiddle.net/NgxvP/1/
在这里,您可以开始使用
EDITED: 来避免附加无序的输入文本字段,但显示它们始终按索引排序,如
dfsq
答案中评论的那样我创建了一个 jsfiddle为了您的方便http://jsfiddle.net/2HA5s/
Here you have something to start playing with
EDITED: to avoid appending unordered input text fields, but showing them always ordered by their index, as commented in
dfsq
answerI created a jsfiddle for your convenience http://jsfiddle.net/2HA5s/