有些浏览器,如Firefox/Chrome,不会保存HTML输入值的当前状态。因此,您必须手动分配输入值:
$( document ).ready(function() {
$( "#_create" ).click(function() {
var myHtml = '<input class="my-input" value="">';
$('#_input').html(myHtml);
});
$( "#_save" ).click(function() {
//if you have many input fields, loop through them all
$("input").each(function(){
//set the value manually
this.setAttribute('value', this.value);
});
alert($('#_masterDiv').html());
});
$( "#_saveIterate" ).click(function() {
$("input").each(function(){
alert(this.value);
});
});
});
这是jsfiddle链接:
http://jsfiddle.net/urspz/1/