Mic*_*ter 9 jquery-mobile cordova
我正在尝试使用phonegap/JQM应用程序中的javascript更改选择值.我按照建议在更改其值后调用.selectmenu('refresh'); 它收到此错误:
在初始化之前,Uncaught无法在selectmenu上调用方法; 试图调用方法'刷新'
如果我删除该调用,则select上的.val()将更改,但屏幕上的图形不会更改..selectmenu("refresh")用于将图形与select的.val()同步.
以下是我尝试使用的两种资源:http : //jquerymobile.com/demos/1.0a3/#docs/forms/plugin-eventsmethods.html http://jquerymobile.com/test/docs/forms /forms-selects.html
我是新的手机和JQM.
以下是尝试每三秒翻转一次选择的示例代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="viewport" content="width=default-width; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Demo Error</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
function onBodyLoad()
{
document.addEventListener("deviceready",onDeviceReady,false);
for (i=1;i<10;i++) {
setTimeout('changeProduct()',i*3000);
}
}
function changeProduct()
{
if ($("#product").val() == 'S')
{
$("#product").val('M');
}
else
{
$("#product").val('S');
}
console.log("calling selectmenu refesh change to " + $("#product").val());
$("#product").selectmenu('refresh', true);
}
/* When this function is called, PhoneGap has been initialized and is ready to roll */
function onDeviceReady()
{
// do your thing!
}
</script>
<link rel="stylesheet" href="jquery.mobile-1.0a3.css" />
<link rel="stylesheet" href="quote.css" />
<script src="jquery-1.5.min.js"></script>
<script src="jquery.mobile-1.0a3.js"></script>
</head>
<body onload="onBodyLoad()">
<div id="page1" data-role="page">
<div data-role="content">
<div id="product-all" data-role="fieldcontain">
<label for="product">Product:</label>
<select data-role="slider" name="product" id="product" value="S">
<option id="one" value="S">Single</option>
<option id="two" value="M" selected="selected">Multi</option>
</select>
</div>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Mic*_*ter 23
我想到了:
如果要使用javascript更改data-role =滑块的值,请在更改值后调用:$('#mysliderid').slider('refresh');
如果要使用javascript更改data-role = select的值,请在更改值后调用:$("#myselectid").selectmenu('refresh',true);
这可能会令人困惑,因为在内部它们都使用select,因此可能会误以为selectmenu对两者都有效.
| 归档时间: |
|
| 查看次数: |
16198 次 |
| 最近记录: |