我对此很困惑。我正在使用jquery 1.9.1将div的内部html附加到另一个div。但是当尝试使用chrome开发人员工具进行调试时,它在jquery库中给了我这个错误。
我的Html:
<body>
<s:form action="/save" method="POST">
<div class="educationForm">
<div class="educations">
<label>Position</label>
<input type="text" name="educations[0].index" value="1" />
<br/>
<label>School</label>
<input type="text" name="educations[0].school" />
<br/>
<label>Degree</label>
<input type="text" name="educations[0].degree" />
<br/>
<label>GPA</label>
<input type="text" name="educations[0].scored" />
<br/>
<label>Start Date</label>
<input type="text" name="educations[0].startDate" />
<br/>
<label>End Date</label>
<input type="text" name="educations[0].endDate" />
<br/>
</div>
</div> <a href="#" id="addButton">Add new Edu</a>
<input type="submit" value="Save" />
</s:form>
<div class="template_educations" style="display:none">
<div class="educations">
<label>Position</label>
<input type="text" name="educations[_X_].index" />
<br/>
<label>School</label>
<input type="text" name="educations[_X_].school" />
<br/>
<label>Degree</label>
<input type="text" name="educations[_X_].degree" />
<br/>
<label>GPA</label>
<input type="text" name="educations[_X_].scored" />
<br/>
<label>Start Date</label>
<input type="text" name="educations[_X_].startDate" />
<br/>
<label>End Date</label>
<input type="text" name="educations[_X_].endDate" />
<br/>
</div>
</div>
</body>
我的js:
$(document).ready(function(){
$("#addButton").click(function(event){
event.preventDefault();
$(".educationForm").append($(".template_educations").html);
$(".educationForm").children(".educations").last().children("input").each(function(){
var count = $(".educationForm").children(".education").length();
var value = $(this).attr("name");
value.replace("_X_", count + 1);
$(this).attr("name", value);
});
});
});
请帮我确定这是否是jquery库中的错误或我的代码有问题,因为我的代码中没有使用任何函数empty
答案 0 :(得分:5)
应该是html()
..而不是html
..
....
$(".educationForm").append($(".template_educations").html());
.... //--^^---here
答案 1 :(得分:2)
使用此行
$(".educationForm").append($(".template_educations").html);
就像
一样 $(".educationForm").append($(".template_educations").html());