我目前正在使用JSP和jQuery手机一起使用Struts。问题是仅在页面刷新一次后才会调用javascript函数。脚本放置在数据角色“页面”中。但问题仍然存在。目前我正在使用jQuery 1.0稳定版本。这里是我的代码..Javascript只能在jQuery手机的页面刷新工作
<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>
上面的代码工作绝对没问题,一旦页面被刷新。一旦它已经被加载,我不想重新加载页面。请帮忙。
你指的是哪一个javascript函数?我看到很多。没有任何事件触发器,函数如何被触发? – Lowkase
@Lokase:手机号码验证正在对提交,checkcount和textarea的按键上的goodchars调用。 getTemplate()用于填充下拉加载。当选择任何选项时,将调用onchange事件以使用下拉列表的值填充textarea。 – Silver