0

在我的 MVC 应用程序中包含了一个名为 form Field 的按钮。每当用户单击该按钮时,下拉列表就会显示在包含文本、复选框等选项的模式框中。

function Select_type(box) {
             var tp = document.getElementById('Type').value;
             switch (tp) {
                 case "Text":
                     {
                     var editor = CKEDITOR.instances.message;
                     editor.insertHtml('<input type="text" id="tx" />'); 
                 }
                     break;
                 case "Checkbox": 
                     { 
                         var editor = CKEDITOR.instances.message;
                         editor.insertHtml(' <input type="checkbox" id="chk" name="chk" />');
                                        } 
                     break;
                 case "Radio": 
                     { 
                 var editor = CKEDITOR.instances.message;
                 editor.insertHtml('<input type="radio" id="rd" name="rd" />');
                   }
                     break;
                 case "DropDown":
                     {
                         var ediotr = CKEDITOR.instances.message;
                         ediotr.insertHtml('<select id="options"></select>');
                         dhtmlx.modalbox({
                             title: "Form Field Properties",
                             text: "<div id='form_in_box'><div ><label>Field Options:<input id='txt'></label><br></div><div><span class='dhtmlx_button'><input type='submit' value='Add' style='width: 86px' onclick='Add_type(this)'></span><span class='dhtmlx_button'><input type='button' value='Cancel' onclick='close_file(this)' style='width:80px;'></span></label></div></div>",
                             width: "300px"
                         });
                     }

                     break;
                 case "Listbox": alert("Listbox");
                     break;
             }              
             dhtmlx.modalbox.hide(box);
         }

当用户选择下拉选项时,会出现一个模式框,允许用户将选项添加到下拉列表

function Add_type(box) {
             var txt = $('#txt').val();
             if (txt.length > 0) {
                 $("#options").append("<option value='" + (txt.length - 1) + "'>" + txt + "</option>")
             }
         }

Textarea 和按钮出现在模态框中,但它不添加用户在 textarea 中输入的选项

4

1 回答 1

1

function Add_type() {
     var txt = $('#txt').val();
     if (txt.length > 0) {
         var lBox = $('select[id$=options]');
         $(lBox ).append("<option value=' " + (txt.length - 1) + " '>" + txt + "</option>")
    }
}

I tried like this, it was working

于 2013-04-02T12:17:10.383 回答