如何在不包含输入值的情况下进行克隆(使用
我试图克隆表单的一部分,而不包含用户输入到第一个表单中的信息。我正在使用字段内标签 jQuery 插件。
当我使用 val('') 解决此问题时,输入的值不会重复,但 In-Field Labels 插件的水印没有按应有的方式显示 - 它只是空白。
有谁对如何解决这个问题有任何建议,甚至如何使我的代码更有效/正确?谢谢。
(function() {
var count = 0;
$('#add-standard-button').live('click',function () {
var source = $('.details'),
clone = source.clone();
clone.find('.copyme').val('').attr('id', function(i, val) {
return val + count;
});
clone.find('.copyme').val('').attr('name', function(i, val) {
return val + count;
});
clone.find('.placeholder').val('').attr('for', function(i, val) {
return val + count;
});
clone.insertAfter('.details:last');
count++;
});
HTML:
<div class="details" id="standard-details">
<div class="markName">
<p>
<span class="markName-field">
<label for="markName" class="placeholder">
<span>Watermark Text Goes Here</span>
</label>
<input type="text" name="markName" id="markName" class="copyme">
</span>
</p>
</div>
</div>
I am trying to clone part of a form without including the information that the user inputs into the first form. I am using the In-Field Labels jQuery Plugin.
When I use val('') to address this problem, the value of the input is not duplicated, but the watermark for the In-Field Labels plugin doesn't appear as it should - it's just blank.
Does anyone have any suggestions on how to resolve this problem, or even how to make the code I have more efficient/correct? Thank you.
(function() {
var count = 0;
$('#add-standard-button').live('click',function () {
var source = $('.details'),
clone = source.clone();
clone.find('.copyme').val('').attr('id', function(i, val) {
return val + count;
});
clone.find('.copyme').val('').attr('name', function(i, val) {
return val + count;
});
clone.find('.placeholder').val('').attr('for', function(i, val) {
return val + count;
});
clone.insertAfter('.details:last');
count++;
});
HTML:
<div class="details" id="standard-details">
<div class="markName">
<p>
<span class="markName-field">
<label for="markName" class="placeholder">
<span>Watermark Text Goes Here</span>
</label>
<input type="text" name="markName" id="markName" class="copyme">
</span>
</p>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在输入上设置标题标签,然后从中提取默认值。
请参阅示例: http://jsfiddle.net/4KLU5/
或者您可以使用 HTML5 数据
标签
Set the title tag on your inputs and then pull your default value from that.
See an example: http://jsfiddle.net/4KLU5/
Or you could use HTML5 data tags
and