[英]JQuery dynamically input fields with sub input fields
stopping my function on javascript在javascript上停止我的功能
By using this I can add unlimited inputs on my page.通过使用它,我可以在我的页面上添加无限的输入。 But the issue is in my case, I have an input field but it may or may not have a child or sub input field and if then it should be associated with the parent input field.
但问题是在我的情况下,我有一个输入字段,但它可能有也可能没有子输入字段或子输入字段,如果然后它应该与父输入字段相关联。
Also parent input field is must for sub input fields.子输入字段也必须使用父输入字段。
Question?问题?
Dynamic input fields(got from above),动态输入字段(从上面获得),
Dynamic child/sub input fields,动态子/子输入字段,
How to associate child/sub input fields with parent,如何将子/子输入字段与父项关联,
So that it can save in the db with related to field.以便它可以保存在与字段相关的数据库中。
Use similar function and append under paragraph with different name, Hope this will be helpful.使用类似的功能并在不同名称的段落下追加,希望这会有所帮助。 Try it.
尝试一下。
http://jsfiddle.net/Shahbaz/WhaBx/ http://jsfiddle.net/Shahbaz/WhaBx/
From this I can add multiple input fields and append multiple sub/child input fields.由此我可以添加多个输入字段并附加多个子/子输入字段。 which can be append.
可以追加。 I'll try to modify more.
我会尝试修改更多。
$(function() {
var scntDiv = $('#p_scents');
var i = $('#p_scents label').size() + 1;
$('#addScnt').live('click', function() {
$('<p>Keyword: '+i+'<a href="#" id="remScnt">Remove</a><br><labelfor="p_scnts"><input type="text" id="p_scnt" size="20" name="keyword[]" value="" placeholder="Enter Keyword" /><a href="#" id="addVar">Add Variants</a><a></a></label></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function() {
if( i >2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
$('#addVar').live('click', function() {
//alert();
$('<p><label for="var"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Enter Vareyword" /></label> <a href="#" id="remVar">Remove Var</a></p>').appendTo($(this).next());
return false;
});
$('#remVar').live('click', function() {
$(this).parent('p').remove();
return false;
});
});
<h2><a href="#" id="addScnt">Add Another Input Box</a></h2>
<div id="p_scents">
<p>
Keyword: 1
<br/>
<label for="p_scnts"><input type="text" id="p_scnt" size="20" name="keyword[]" value="" placeholder="Enter keyword">
<a href="#" id="addVar">Add Variants</a>
</label>
</p>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.