2011-07-08 38 views
1

我在html(SelectTest.html)中创建了一些select.get标签,我试图做的是从选择标签中选择任何值后,我需要页面刷新并将所选选项作为参数传递给url。无法设置jquery mobile中选择标签的值

然后,我需要将页面刷新后设置为选定值。我不确定这个问题是否与jQuery mobile有关。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 

    var param = window.location.search; 

    if(param) 
    { 


     var indx = param.indexOf("="); 

     //now get the value of selected type 

     aval =param.substring(indx+1); 

     $("#lang").val(aval); 
    } 

    $("#lang").change(function(){ 

     var sel = $(this).val(); 


     window.location.href="SelectTest.html?type="+sel; 

     }); 

}); 



</script> 
<title>Insert title here</title> 
</head> 
<body> 
<div data-role="page" id="home" data-theme="e"> 
<div data-role="header"> 
<h1>Test</h1> 
</div> 
<div data-role="content" id="toi"> 

<div> 
<label for="lang">Select Language</label> 
<select name="language" id="lang"> 
<option value="en">English</option> 
<option value="hi">Hindi</option> 
<option value="sp">Spanish</option> 
<option value="fr">French</option> 
</select> 
</div> 



<div id="main"> 

</div> 
</div> 
</div> 
<div data-role="footer"> 
<h4>Test</h4> 
</div> 
</div> 
</body> 
</html> 
+0

对我的作品在Chrome,所以是的,它可能是在移动 – Mrchief

+0

一个问题是吗?即使我尝试铬,但没有运气。该选项即使在页面刷新后也被更改。对我而言,每次只有英文选项被选中 – JavaGeek

+0

它适用于每个选项。也许你在页面上还有其他的东西? – Mrchief

回答

4

从jQuery Mobile的文档:

如果通过 JavaScript操作一个选择,你必须调用它的刷新 方法来更新视觉 造型。这里有一个例子:

var myselect = $("select#foo"); 
myselect[0].selectedIndex = 3; 
myselect.selectmenu("refresh"); 

所以基本上你只需要调用它的刷新。这有帮助吗?

对于你的代码可以连续使用像这样

$('#lang').val(aval).selectmenu("refresh"); 
+0

哇..它为我工作..感谢很多乔纳森 – JavaGeek

+0

没问题!我有与滑块相同的问题...滑块的语法略有不同。我相信它是'.slider(“刷新”)'。 –

相关问题