第一次双击按钮的时候,追加的文本框出现了,再次双击的时候,又消失了, 这是为什么呢?
@model Vote.Models.
VoteDetailModel
@{
ViewBag.Title =
"VoteUpdate";
}
<h2>Vote Update</h2>
@section BodyEnd{
<scriptsrc="../../Scripts/jquery-2.1.0.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(document).ready(
function () {
var fieldCount = 1;
$('#btnAddItem').click(function (e) {
var $div = $('<div/>');
var $newInput = $('<input/>', {
type:'text',
id:'txt_' + fieldCount
});
$('#addItems').append($div).append($newInput);
fieldCount++;
});
});
</script>
}
@*
@Html.TextBoxFor(m => m.VoteItems[0])@Html.ValidationMessageFor(m => m.VoteItems[0])*@
@
using (Html.BeginForm()){@Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
<div>
<fieldset>
<legend>Update Vote Items</legend>
<divclass="editor-label">
@Html.LabelFor(m => m.VoteTitle)
</div>
<divclass="editor-field">
@Html.TextBoxFor(m => m.VoteTitle)
@Html.ValidationMessageFor(m => m.VoteTitle)
</div>
<divclass="editor-label">
@Html.LabelFor(m => m.VoteItems)
</div>
<divid="addItems">
<div>
<inputid="txt_0"type="text"/>
</div>
</div>
<inputid="btnAddItem"type="submit"value="+"/>
<p>
<inputtype="submit"value="Save"/>
</p>
</fieldset>
</div>
}