javascript - 在 jquery mobile 中动态选择组合框

标签 javascript jquery ajax html jquery-mobile

我想将数据库中的值附加到选项标签组合框上。但是,当我第一次将选项标记的值设置为空,然后通过 AJAX 附加时,它只显示一个值。但我希望所有选项都应该可见,但应该自动选择一个选项。

我的代码

$('#b').on("click", "a", function () {
    var patid= $(this).attr('id');
    $.ajax({
    type:"GET",
    url:"https://localhost/patient_details1.php?patid="+patid,
    dataType:'JSON',
    success:function(response)
    {
      ("#pat_type").html("");
       for (var i=0;i<response.length;i++) 
          {
            $('<option value="'+ response[i].pattype +'">'+ 
    response[i].pattype +'</option>').appendTo("#pat_type");
                    }
          }
    }
    });             
}); 

最佳答案

  1. 使用 $('#pat_type').empty()。
  2. 检查您何时从请求中获取数据。你需要得到它 仅在加载页面后。

关于javascript - 在 jquery mobile 中动态选择组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28404667/

相关文章:

javascript - React-bootstrap-autosuggest 的问题

javascript - webpack:在 MacOS 上正常,在 linux 上加载程序错误

javascript - ReactJS的疑惑和疑问

ajax - 使用ajax检测HTTP错误

javascript - 如何在 jQuery 幻灯片更改时创建 ajax 调用?

javascript - 如何获取 Firebase Cloud Firestore 中存在/不存在特定字段的文档?

jquery - 在 jPlayer 中播放通过 Paperclip 上传的歌曲 - Ruby on Rails - jQuery - jPlayer

jquery - 我怎样才能知道用户是否正在尝试打印

javascript - 附加图像时水平和垂直居中的 div 'jumping'

javascript - 用 Ajax 替换 Iframe