在移动应用程序中使用jquery填充下拉列表 [英] populate drop down with jquery in mobile app

查看:54
本文介绍了在移动应用程序中使用jquery填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是移动开发的新手,并尝试使用country_name填充下拉列表

任何帮助都将受到赞赏。





这是我从网络服务返回的xml数据



 < ;   NewDataSet  >  
< script / >
< >
< 详细信息 >
< country country_sk = 2 currency_sk = 165 country_name = 阿富汗 country_telecom_code = 93 country_code = AF / > < country country_sk = 5 currency_sk = 166 country_name = 阿尔巴尼亚 country_telecom_code = 355 country_code = AL / > < country country_sk = 62 currency_sk = 167 country_name = 阿尔及利亚 country_telecom_code = 213 country_code = DZ < span class =code-attribute> / > < country country_sk = 11 currency_sk = < span class =code-keyword> 70 country_name = 美属萨摩亚 country_telecom_code = 1684 country_code = AS < span class =code-attribute> / > < country country_sk = 6 currency_sk = 213 country_name < span class =code-keyword> = 安道尔 country_telecom_code = 376 country_code = AD / > < country country_sk = 3 currency_sk = 169 country_name = 安哥拉 country_telecom_code = 244 country_code = AO / > < country country_sk = 4 currency_sk = < span class =code-keyword> 211 country_name = 安圭拉 country_telecom_code = 1264 country_code = AI / >


我正在尝试使用以下代码在下拉列表
中填充country_name,但它无效。

< script > ;
$(document).ready(function(){
$ .ajax({
type:GET,
url:http:// www.xyz.mobwebservice.asmx / countryList,
dataType:xml,
成功:函数(xml){
var select = $('#mySelect');
$(xml).find('country')。each(function(){
var id_text = $(this).attr('country_sk')
var name_text = $(this).find ('country_name')。text()

var option = $(< 选项 > + name +< / option > );
option.attr(value,value);
select.append(option );
}); //关闭每个(
select.children(:first)。text(请选择)。attr(selected,true);
} //关闭$ .ajax
});
});
< / script >
< / head >
< body > ;
< 表格 id = form1 >
< select id = mySelect >
< 选项 > loading < / option >
< / select >
< / form >
< / body >
< / html >

帮助我非常紧急

解决方案

(文件).ready(function(){


< blockquote> .ajax({
type:GET,
url:http://www.xyz.mobwebservice.asmx/countryList,
dataType: xml,
成功:function(xml){
var select =


('#mySelect');


I am new to mobile development and trying to populate drop down list with country_name
any help would be appreciated.


This is my xml data returned from web services

<NewDataSet>
<script/>
<Table>
<detail>
<country country_sk="2" currency_sk="165" country_name="Afghanistan" country_telecom_code="93  " country_code="AF" /><country country_sk="5" currency_sk="166" country_name="Albania" country_telecom_code="355 " country_code="AL" /><country country_sk="62" currency_sk="167" country_name="Algeria" country_telecom_code="213  " country_code="DZ" /><country country_sk="11" currency_sk="70" country_name="American Samoa" country_telecom_code="1684  " country_code="AS" /><country country_sk="6" currency_sk="213" country_name="Andorra" country_telecom_code="376  " country_code="AD" /><country country_sk="3" currency_sk="169" country_name="Angola" country_telecom_code="244  " country_code="AO" /><country country_sk="4" currency_sk="211" country_name="Anguilla" country_telecom_code="1264  " country_code="AI" />


I am trying to populate country_name in drop down list
with following code but its not working.

<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://www.xyz.mobwebservice.asmx/countryList",
dataType: "xml",
success: function(xml) {
				var select = $('#mySelect'); 
                 $(xml).find('country').each(function(){
                     var id_text = $(this).attr('country_sk')
                     var name_text = $(this).find('country_name').text()

                     var option = $("<option>" + name + "</option>"); 
                         option.attr("value", value); 
                         select.append(option);
                 }); //close each(
                 	select.children(":first").text("please make a selection").attr("selected", true);
             } //close $.ajax
}); 
}); 
</script>
</head>
<body> 
    <form id="form1"> 
      <select id="mySelect"> 
              <option>loading</option> 
      </select> 
    </form> 
</body>
</html>

help me its very urgent

解决方案

(document).ready(function(){


.ajax({ type: "GET", url: "http://www.xyz.mobwebservice.asmx/countryList", dataType: "xml", success: function(xml) { var select =


('#mySelect');


这篇关于在移动应用程序中使用jquery填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆