由于某些原因,我试图获取元素的attr时未定义。不知道我在这里做错了什么。
这是代码:
var $lastFormGroupLast = $multipleFormGroup.find('.form-group:last');
$id = $lastFormGroupLast.attr('id');
c = $id.substr($id.length - 1);
c = parseInt(c);
$formGroupClone.attr('id', 'id'+(++c) );
$formGroupClone.insertAfter($formGroup);
这是html:
<form id="id0" class="form-group multiple-form-group input-group form-inline" style="width: 585px;">
<div class="input-group">
<div class="input-group-addon">http://</div>
<input style="width: 170px; margin-right: 5px;" type="text" name="url[]" class="form-control pull-left web_url" placeholder="type website url">
</div>
<div class="input-group">
<input style="width: 95px; margin-right: 5px;" type="text" name="url[]" class="form-control pull-left width" placeholder="1024px">
</div>
<div class="input-group">
<input style="width: 95px; margin-right: 5px;" type="text" name="url[]" class="form-control pull-left height" placeholder="600px">
</div>
<input class="thathidden" type="hidden" name="base_id" value="<?php echo $deet[0]->id; ?>">
<span class="input-group-btn">
<button type="submit" class="btn btn-alert btngrab">Grab</button>
</span>
<span class="input-group-btn">
<button type="button" class="btn btn-success btn-add">Add New</button>
</span>
</form>