【发布时间】:2011-08-15 14:48:00
【问题描述】:
我也在尝试在添加输入字段时添加此 HTML:
<div id="redDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:red;"></div>
<div id="greenDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:green;"></div>
我未编辑的 Jquery http://jsfiddle.net/gDChA/23/:
function findLastInput ( element ) {
return $( element ).parent().prev().find('input').last();
}
$('button.add').click ( function(e) {
$(this).parent().find('button.remove').show();
$(this).hide();
var element = findLastInput(this).clone();
var name = element.prop('name');
var pattern = new RegExp(/\[(.*?)\]/);
var info = name.match(pattern)[1];
element.prop({
'value': '',
'name' : name.replace(pattern, '[' + info + 'info' + ']'),
'id' : element.prop('id') + 'info',
'type' : 'input',
'class' : 'infoinput'
});
$(this).parent().append(element);
})
$('button.remove').click ( function(e) {
$(this).parent().find('button.add').show();
$(this).hide();
//findLastInput(this).remove('input');
$(this).parent().find("input").remove();
});
首先,我尝试添加额外的 HTML,但没有运气。我已经编辑了这个$(this).parent().append(element);
对此,它不起作用:
$(this).parent().append(element + '<div id="redDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:red;"></div>
<div id="greenDiv" style="width:30px;height:30px;margin-top:10px;display:block;background:green;"></div>');
我想添加 HTML 并以与输入字段相同的方式将其删除。
【问题讨论】:
标签: javascript jquery html jquery-ui jquery-selectors