首页 新闻 会员 周边 捐助

.net MVC 动态追加Html元素

0
[已关闭问题] 关闭于 2019-08-12 16:05

第一次双击按钮的时候,追加的文本框出现了,再次双击的时候,又消失了, 这是为什么呢?

 

@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>

}

小柑的主页 小柑 | 初学一级 | 园豆:6
提问于:2016-04-03 23:53
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册