gpt4 book ai didi

Javascript 仅适用于 jQuery mobile 中的页面刷新

转载 作者:行者123 更新时间:2023-12-02 19:25:45 29 4
gpt4 key购买 nike

我目前正在使用 jquery mobile、JSP 和 Struts。问题是javascript函数只有在页面刷新一次后才会被调用。该脚本放置在数据 Angular 色“页面”内。但问题仍然存在。目前正在使用 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

关于Javascript 仅适用于 jQuery mobile 中的页面刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12074364/

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