0
我有一個對話框彈出窗口,其中有幾個字段。這個對話框從php文件中檢索。 我可以從所有這些val(),但下拉。無法從對話框中使用jquery檢索下拉選擇的值
摘錄:
呼叫對話框:
$('#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');
}
});
出於某種原因,$('#inputCategory')。val()和$('#inputVersion')。val()是空的,而文本區域沒有問題。
也嘗試添加一個onChange函數來警告更改下拉...它不會觸發。
的形式似乎是正確生成:
<li><label for="Category">Category</label><select id="inputCategory" class="text ui-widget-content ui-corner-all">
只是想不通爲什麼不能抓住這些值:)
似乎不是幫助..他們還是拿出空後。 – MarlonB
好吧.. PLZ請給我流量..當你點擊'createNote'時會出現一個對話框。之後,你將選擇下拉的東西,其中包含動態值。您正在獲取下拉列表中的Val(),並且正在關閉對話框。儀式? – Arun
這是正確的。但是當我嘗試獲得它時val總是空的。它可能是一個時間問題? ...我做了.post,然後窗戶關閉了。我幾次注意到,當我在一張桌子上做了一個fnDraw()函數之前,我用.post更新了這行,但它通常不會做這些修改。 – MarlonB