我有一个我这样创建的模态表单:
function addeditNote(rowID,callback) {
var ret;
jQuery.fancybox({
modal : true,
overlayOpacity : 0.25,
content : "<div class=\"contentbox modal-window modal-400\"><div class=\"boxbody\"><div class=\"boxheader clear\"><h2>Add / Edit User Notes</h2></div><br /><div class=\"box-wrap clear\"><form action=\"\" method=\"post\" class=\"form bt-space0\"><div class=\"columns clear bt-space0\"><div class=\"colText fl\"><div class=\"form-field clear\"><label for=\"textfield\" class=\"formlabel size-20 fl-space2\">Name: </label><input type=\"text\" id=\"name\" class=\"text fl-space2\" /></div><div class=\"form-field clear\"><div class=\"fl-space2\"><label for=\"textarea\" class=\"formlabel size-20\">Notes: </label></div><textarea id=\"note\" class=\"form-textarea display\" cols=\"50\" rows=\"6\" name=\"form[note]\" rel=\"textarea\"></textarea></div></div></div><div class=\"columns clear bt-space5\"></div><div class=\"form-field clear\"><input id=\"addeditNote_cancel\" class=\"button fr-space2\" type=\"button\" value=\"Cancel\"><input id=\"addeditNote_ok\" class=\"button green fr-space\" type=\"button\" value=\"Enter\"></div></form></div><!-- end of box-wrap --></div> <!-- end of box-body --></div>",
onComplete : function() {
jQuery("#addeditNote_cancel").click(function() {
ret = false;
jQuery.fancybox.close();
})
jQuery("#addeditNote_ok").click(function() {
ret = true;
jQuery.fancybox.close();
})
},
onClosed : function() {
callback.call(this,ret);
}
});
}
我的json字符串如下:
$.getJSON("GetNotes.php?id=" + rowID,
function(data) {
$.each(data, function(i, item) {
$('#' + item.field).val(item.value);
});
});
返回:
{"op": "UPDATE", "id": "7","name": "Joe Public","note": "Dennis likes his coffee in the morning... He doesn't drink tea and coffee always have powdered creamer and 2 sugar's." }
“op”只是一个占位符所以我知道如果一个注释存在于他们我正在更新数据库,如果它不是它们我正在插入..
我的问题是,我不知道如何把它填入表格中......我还在学习,所以希望有人能给我一个如何运作的线索.. :)
谢谢! 丹尼斯
答案 0 :(得分:1)
如果在创建窗口的同一函数中填充表单不起作用,请尝试在onComplete处理程序中将其作为调用添加:
onComplete : function() {
//All of your original code here
$.getJSON( /* with your JSON code here */ );
},
据推测,对话框应该准备就绪,您可以正常地将内容加载到表单元素中。