我有一个对话框弹出窗口,里面有几个字段。从php文件中检索此对话框。 除了下拉列表,我可以从所有这些中获取val()。
代码段:
致电对话框:
$('#createNote').click(function(e){
e.preventDefault();
$.ajax({ url: 'functions.php',
type: 'POST',
data: {"function": "createNoteDialog"},
success: function(data){`enter code here`
$('#dialog-form').html(data);
$('#dialog-form').dialog('open');}
});
});
生成表单:
if ($func == "createNoteDialog" ){
echo '<form class="cmxform"><fieldset>';
echo '<li><label for="Category">Category</label><select id="inputCategory" class="text ui-widget-content ui-corner-all">';
$r_categories = mysqli_query($global_dbh,'select category from pledges.patchCategories order by 1 asc');
$first_row = mysqli_fetch_row($r_categories);
echo '<option value="' . $first_row[0] . '" selected>' .$first_row[0] . '</option>';
while(($row = mysqli_fetch_array($r_categories)) != false) echo '<option value="' . $row[0] . '">' .$row[0] . '</option>';
echo '</select>';
echo '<label for="Version">Version </label><select id="inputVersion" class="text ui-widget-content ui-corner-all">';
$r_versions = mysqli_query($global_dbh,'select version from pledges.patchVersions order by 1 desc');
$first_row = mysqli_fetch_row($r_versions);
echo '<option value="' . $first_row[0] . '" selected>' .$first_row[0] . '</option>';
while(($row = mysqli_fetch_array($r_versions)) != false) echo '<option value="' . $row[0] . '">' .$row[0] . '</option>';
echo '</select>';
echo '<li><label for="DevNote">Dev Note </label><textarea id="inputDevNote" name="DevNote" cols=60 rows=7></textarea></li>';
echo '<li><label for="BuildNote">Build Note </label><textarea id="inputBuildNote" name="BuildNote" cols=60 rows=7></textarea></li>';
echo '<li><label for="Comment">Comment </label><textarea id="inputComment" name="Comment" cols=60 rows=6></textarea></li>';
echo '</fieldset></form>';
}
保存:
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 700,
width: 800,
modal: true,
buttons: {
"Create Note": function() {
$.post( "functions.php"
, { "function": "saveNote" , "version": $("#inputVersion").val(), "category": $('#inputCategory').val() ,"devNote": $('#inputDevNote').val() ,"buildNote": $('#inputBuildNote').val() ,"comment": $('#inputComment').val()});
patchNotesTable.fnDraw();
$( this ).dialog( "close" );
},
"Cancel": function() {
$( this ).dialog( "close" );
}
},
close: function() {
$(this).dialog('close');
}
});
由于某种原因,$(&#39; #inputCategory&#39;)。val()和$(&#39; #inputVersion&#39;)。val()为空,而文本区域为&#39;没事。
还尝试添加onChange函数来提醒下拉列表的更改...它不会触发。
表格似乎是正确生成的:
<li><label for="Category">Category</label><select id="inputCategory" class="text ui-widget-content ui-corner-all">
无法弄清楚为什么它无法抓住这些价值观:)
答案 0 :(得分:0)
试试这个。
创建另一个
在对话框中<div class="loop">...</div>
。把你所有的东西放进去&#34;循环&#34;。
之后尝试在ajax之后重新加载此部门,点击
之后$('#createNote').click(function(e){
e.preventDefault();
$.ajax({ ...
...
...
});
$(".loop").load("functions.php .loop", {"function": "saveNote" , "version": $("#inputVersion").val(), "category": $('#inputCategory').val() ,"devNote": $('#inputDevNote').val() ,"buildNote": $('#inputBuildNote').val() ,"comment": $('#inputComment').val()});
});