gpt4 book ai didi

javascript - 动态地将数据放入选择选项下拉列表(jQuery)

转载 作者:太空狗 更新时间:2023-10-29 13:35:37 25 4
gpt4 key购买 nike

代码如下:这是我从 XML 中获取数据的情况(这有效,已经在没有 jQuery 的情况下对其进行了测试):

 <script>
$(document).ready(function(){
var select = $('#mySelect');

$.ajax({
type: "GET",
url: "http://mobile.qmschrysant.nl/keuzemenu/keuzemenu.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('menuitem').each(function(){
var title = $(this).find('title').text();
select.append("<option/><option class='ddheader'>"+title+"</option>");
$(this).find('value').each(function(){
var value = $(this).text();
select.append("<option class='ddindent' value='"+ value +"'>"+value+"</option>");

});
});
select.children(":first").text("please make a selection").attr("selected",true);
select.trigger('updatelayout');
}
});
});
</script>

这是我的选择选项 (HTML):

<label for="selectmenu" class="select">Kies planning:</label>
<form>
<select id="mySelect" >

<option>loading</option>
</select>
</form>

现在奇怪的是,当我包含这个 jQuery 脚本时:

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>

然后下拉列表看起来很棒,但不包含任何信息。
当我注释掉该行时,下拉列表看起来很正常,但现在它确实包含信息(所以这证明它确实有效)。

但是为什么当我包含 jQuery 行时它不起作用?我找不到问题。

(请看图片以获得更好的解释) enter image description here

编辑:所有包括我使用的:

<link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

最佳答案

OP“使用了最新的 jquery mobile.js,现在一切正常”。

这似乎是一个兼容性问题。

更改:

<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js" type="text/javascript"></script>
<link href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css">

到:

<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js" type="text/javascript"></script>
<link href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" rel="stylesheet" type="text/css">

关于javascript - 动态地将数据放入选择选项下拉列表(jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10992153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com