Javascript 如何向调用元素添加/编辑对话框表单的修改内容
我试图创建一个可拖动的选择选项,当它被拖动到主内容区域时,我在其中添加了两个控件,一个用于删除拖动的元素,另一个用于删除其属性。可拖动选择的Html如下所示Javascript 如何向调用元素添加/编辑对话框表单的修改内容,javascript,jquery,jquery-ui,jquery-ui-dialog,Javascript,Jquery,Jquery Ui,Jquery Ui Dialog,我试图创建一个可拖动的选择选项,当它被拖动到主内容区域时,我在其中添加了两个控件,一个用于删除拖动的元素,另一个用于删除其属性。可拖动选择的Html如下所示 <div class="demo"> <div class="tools"> <ul> <li class="draggable" > <div class="control"> <label class="orig"> 
<div class="demo">
<div class="tools">
<ul>
<li class="draggable" >
<div class="control">
<label class="orig"> </label>
<select><option> Select Option</option></select>
<div class="delete" style="display:none"><sup>x</sup></div>
<div class="properties select" style="display:none">Properties</div>
</div>
</li>
</ul>
</div>
</div>
现在的问题是,用户在选项中添加的内容没有添加到已拖动到内容区域的选择选项中。
正如您在这里看到的,标签正在更新,但我不知道如何添加/编辑用户在对话框表单中添加的选项。
请帮我解决这个问题。我已经解决了如何添加的问题,这是代码
// Add the Options to the Select Element Here
$('input[name=select_option]').each(function(){
// get the Values of options here
$(this).attr("value", $(this).val());
if($(this).val() != "")
{// if the option is not empty
// add options to the select element
$elem_clicked.find('select').append('<option value="'+$(this).val()+'" >'+$(this).val()+'</option>');
}
});
//将选项添加到此处的Select元素
$('input[name=select_option]')。每个(函数(){
//在这里获取选项的值
$(this.attr(“value”,$(this.val());
if($(this.val()!=“”)
{//如果选项不是空的
//向“选择”元素添加选项
$elem_clicked.find('select').append(“”+$(this.val()+“”);
}
});
<div id="dialog-select" title="Select Properties" style="display:none">
<form>
<fieldset>
<label for="select_label">Enter Label </label>
<input type="text" name="select_label" id="select_label" class="text ui-widget-content ui-corner-all" />
</fieldset>
<fieldset>
<label for="select_option">Option</label>
<input type="text" name="select_option" class="text ui-widget-content ui-corner-all" />
</fieldset>
<fieldset>
<input type="button" name="add_more" id="add_more" value="Add More Option" />
</fieldset>
</form>
$("#dialog-select").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Apply": function(){
var label = $("#select_label").val()
var $elem_clicked = $("#dialog-select").data('parent_div');
$elem_clicked.find('label').html(label);
// I need something to do here
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
// Add the Options to the Select Element Here
$('input[name=select_option]').each(function(){
// get the Values of options here
$(this).attr("value", $(this).val());
if($(this).val() != "")
{// if the option is not empty
// add options to the select element
$elem_clicked.find('select').append('<option value="'+$(this).val()+'" >'+$(this).val()+'</option>');
}
});