使用jQuery/jQueryUI我想用下面的HTML/JS顯示填充表單。.get返回的數據形式允許.html填充表單?
url「editController/loadContents」將返回一些數據,而.html將(根據數據填充表單),但數據應具有哪些結構?
我可以在jQueryUI doco中找到的唯一示例是單元素窗體。
我的猜測是,一些JSON它看起來像這樣...
{
"starttime": "10:00",
"endtime": "11:00",
}
...將填充輸入字段。但是,如何提供SELECT選項,並將選項之一指定爲「選定」?
<div id="dialog" title="Basic dialog">
<!-- loaded from ajax call -->
<form id="exampleForm">
<fieldset>
<label for="activity">Activity</label>
<br />
<select name="activity" id="activity" class="ui-widget-content ui-corner-all">
</select>
<br />
<label for="subactivity">Sub-Activity</label>
<br />
<select name="subactivity" id="subactivity" class="ui-widget-content ui-corner-all">
</select>
<br />
<label for="activity">Reason</label>
<br />
<select name="reason" id="reason" class="ui-widget-content ui-corner-all">
</select>
<br />
<label for="starttime">Start</label>
<br />
<input type="text" name="starttime" id="starttime" class="text ui-widget-content ui-corner-all" />
<br />
<label for="endtime">End</label>
<br />
<input type="text" name="endtime" id="endtime" class="text ui-widget-content ui-corner-all" />
<br />
</fieldset>
<input type="button" onclick="Save()" />
</form>
</div>
<script>
$(function() {
$('.myPop').click(function() {
$.get("editController/loadContents", function(data){
$("#dialog").html(data);
});
$("#dialog").dialog('open');
});
});
function Save(){
$.post("/editController/Edit", $("#exampleForm").serialize(),
function(data){
$("#dialog").dialog('close');
//update grid with ajax call
});
}
</script>
BTW我已經適應在How to use a jQuery UI Modal Form from ASP.Net MVC list page
非常感謝非常有用的答案 - 我對謙卑的.html抱有更高的期望,而不是合理的! – shearichard