单击按钮时MVC复制文本区域

时间:2017-04-19 10:25:19

标签: javascript jquery asp.net-mvc asp.net-mvc-4 clone

我正在尝试让用户在文本区域中选择插入数据,并且还可以通过单击按钮复制文本区域,然后将创建重复的空文本区域。我现在遇到的问题是,一旦用户克隆了textarea,它就会用前一个文本区域的数据复制文本区域。与Jquery一点苦苦挣扎,会感谢一些帮助提前感谢你。

<div id ="specdiv ">
    <fieldset class="fieldset">
        <legend class="legend">Question Specification</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.OfferedAnswer)
        </div>
        <div class ="answerchoice1" id="copybox">
            <div class="editor-field" >
                @Html.TextAreaFor(model => model.OfferedAnswer.AnswerText)
            </div>
        </div> 
    </fieldset>
</div>

Jquery代码:

$("#dialog-message").hide();
$(document).ready(function () {
    $('button').click(function () {
    //$('.answerchoice1').before($('.answerchoice1').clone())
    if ($('.editor-field').length >= 10) {
        // alert('No more than 6!');
        //  $("<div title='Answers Limit has been reached'> You cannot add more anwer choice if you would like to add more please consider to create a new question. Thank you </div>").dialog(       
        //  ).css('border','2px solid red');
        $("#dialog-message").dialog({
            modal: true,
            draggable: true,
            resizable: false,
            position: ['center', 'bottom'],
            show: 'blind',
            hide: 'blind',
            width: 400,
            dialogClass: 'ui-dialog-osx',
            buttons: {
                "I've read and understand this": function () {
                         $(this).dialog("close");
                         }
            }
        });

        return false;
     }
     var $target = $('.answerchoice1').find('div.editor-field:first');
     $target.clone().appendTo('.answerchoice1').find("editor-field").val("");
     $target.find('.answerchoice1').val("");
     $target.insertAfter(".div.editor-field:last")  
     })  
 });

0 个答案:

没有答案