簡體   English   中英

無法使用jquery從對話框的下拉列表中檢索選定的值

[英]Can't retrieve selected value from dropdown in dialog using jquery

我有一個對話框彈出窗口,其中有幾個字段。 此對話框是從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');
      }
    });

由於某些原因,$('#inputCategory')。val()和$('#inputVersion')。val()為空,而文本區域也可以。

還嘗試添加onChange函數來警告下拉菜單的更改...它不會觸發。

該表格似乎是正確生成的:

<li><label for="Category">Category</label><select id="inputCategory" class="text ui-widget-content ui-corner-all">

只是無法弄清楚為什么它無法獲取這些值:)

嘗試這個。

在對話框中創建另一個<div class="loop">...</div> 並將所有內容放入“循環”中。

之后,在點擊后,嘗試在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()});

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM