Javascript仅适用于jQuery mobile中的页面刷新
Javascript working only on page refresh in jQuery mobile
我目前正在使用jquery mobile,它带有JSP和Struts。问题是javascript函数只有在页面刷新一次之后才会被调用。脚本被放置在数据角色"page"中。但问题仍然存在。目前我使用的是jQuery 1.0稳定版本。这是我的密码。。
<body>
<div data-role="page" id="webtosms">
<script language="javascript">
function phonenumlen(){ //Mobile no validation
var numlen = mobileno.value.length;
//alert(numlen);
if(numlen==0){
alert('Mobile Number cannot be left blank');
return false;
}
else if(numlen<10)
{
alert('Mobile number cannot be less than 10 digits');
return false;
}
else
{
//alert('true');
return true;
}
}
function goodchars(e,goods){ // restrict users from entering letters in the mobile number textbox
var key, keychar;
key = getkey(e);
if (key == null) return true;
// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();
// check goodkeys
if (goods.indexOf(keychar) != -1)
return true;
// control keys
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
return true;
return false;
}
function getkey(e)
{
if (window.event)
return window.event.keyCode;
else if (e)
return e.which;
else
return null;
}
langId = 'EN';
messageLen = 299;
message = "";
function checkCount() {
//alert('function called');
if(document.webtosms.message.value.length <= messageLen) {
message = document.webtosms.message.value;
document.webtosms.charcount.value = (messageLen - document.webtosms.message.value.length);
}else {
document.webtosms.message.value = message;
}
}
function getTemplate(){ // code to populate the drop down and display in the textarea
var where_is_mytool=document.forms[0].cboTemplate.value;
var mytool_array=where_is_mytool.split("~");
//alert(where_is_mytool);
alert(mytool_array);
window.document.forms[0].smsa.value=mytool_array[0];
window.document.forms[0].tmplid1.value=mytool_array[1];
window.document.forms[0].title2.value=mytool_array[1];
window.document.forms[0].hidlang.value=mytool_array[2];
window.document.forms[0].hidcreatedbyval.value=mytool_array[5];
}
</script>
</div>
一旦刷新页面,上面的代码就可以正常工作。一旦页面已经加载,我不想重新加载它。请帮忙。
在包含jQuery之后,但在调用jQuery mobile之前,您需要将所有javascript放在head部分。
您的头文件应该与此类似(第二个文件中的自定义JS):
<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://www.example.com/path-to-file/custom-javascript.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
更新
在页面的链接上,添加属性data-ajax="false"
。如果您想在整个站点范围内禁用Ajax导航,请在自定义JS文件中放入以下代码:
$(document).bind("mobileinit", function(){
$.extend( $.mobile , {
ajaxEnabled: false
});
});
以下是文档链接:http://jquerymobile.com/demos/1.1.1/docs/api/globalconfig.html
对我来说,将数据ajax="false"放在包含脚本的页面的所有链接上。
相关文章:
- Javascript仅适用于jQuery mobile中的页面刷新
- Jquery Mobile Onclick事件在刷新前不起作用
- 在'之后刷新jQuery Mobile元素;手动'操纵
- 如何在Jquery Mobile中刷新页面时使用Coldfusion toScript
- jQuery Mobile 在数据库查询后刷新列表视图
- 当我在 collapsible-set 中添加代码时,如何在 jquery Mobile 中刷新 collapsible
- jQuery Mobile 嵌套列表刷新解决方案
- JQuery Mobile - 跨度刷新在 li 内
- 刷新 JQuery Mobile 中的列表视图和复选框
- 将 iDangero.us Swiper与jQuery Mobile一起使用时需要刷新页面
- jQuery Mobile中AJAX请求后刷新页面
- jQuery Mobile列表视图样式在清空并动态重新创建列表项后不刷新
- JQuery mobile:在页面刷新后运行代码
- jQuery Mobile弹出窗口获胜't在页面导航后显示,仅在硬刷新或返回同一页面后显示
- JQuery Mobile/Webkit-刷新和返回按钮事件后保留Dom状态
- 如何在页面调整上刷新jQuery Mobile样式
- Jquery mobile-使用pageinit刷新复选框
- 如何在Jquery Mobile 1.4.5中刷新新的Div内容
- 刷新jquery mobile中的弹出内容
- Mobile Safari:JS事件,用于在刷新时跳转到最后一个滚动位置