你擁有的PHP運行第一頁就需要
$(document).on("pagebeforeshow", "#yourpageid", function() {
)};
這隻會在你的php select是通過jquery調用創建時才起作用。在我的情況下,我發現創建jQuery元素與PHP結果是從長遠來看更容易。
在我的情況我有這個。
<div data-role="fieldcontain">
<script type="text/javascript">
$(document).on("pagebeforeshow", "#index4", function() {
$(function(){
var items="";
$.getJSON("ajaxResponder.php?method=getContacts",function(data){
$.each(data,function(index,item)
{
items+="<option value='"+item.email+"'>"+item.username+"</option>";
});
$("#contacts").html(items);
$("#contacts").trigger("change");
});
});
});
</script>
<select name="contacts[]" id="contacts" multiple="multiple" data-native-menu="false">
</select>
</div>
沒有任何代碼示例以及如何編寫代碼,這是我的最佳答案。