使用javascript验证无法在phonegap中使用 [英] Validation is not working in phonegap using javascript

查看:63
本文介绍了使用javascript验证无法在phonegap中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Here is the Code:
 <form id="form" method="POST" onSubmit="return submitForm()" data-ajax="false">
        <div class="XYZinfo">
        <label><b> XYZ Information</b></label><hr>
             <label for="firstname">First Name:</label>
            <input type="text" name="firstname" id="firstname" value="" placeholder="">
            <label for="lastName">Last Name:</label>
            <input type="text" name="lastname" id="lastName" value="" placeholder="">
            <label for="address">Address:</label>
            <input type="text" name="address" id="address" value="" placeholder="">
            <label for="apt">Apt:</label>
            <input type="text" name="apt" id="apt" value="" placeholder="">
            <label for="city">City:</label>
            <input type="text" name="city" id="city" value="" placeholder="">
</div>
 </form>

and the javascript code which i am using in the submit form is :


function submitForm()
 {

  var fname= $("[id='firstname']").val();
  var lname= $("[id='lastname']").val();
  var _address= $("[id='address']").val();
  var _apt= $("[name='apt']").val();
  var _city= $("[name='city']").val();

  window.localStorage.setItem("firstname",fname);
  window.localStorage.setItem("lastname",lname);
  window.localStorage.setItem("address",_address);
  window.localStorage.setItem("apt",_apt);
  window.localStorage.setItem("city",_city);

  if(fname == " ")
 {
alert('please the first name');
return false;
 }

else
  {
  $.mobile.changePage("#page2",{ reverse:false, transition:"slide"});

  $("#buyerData").html("FirstName:" + window.localStorage.getItem("firstname") +"<br>"+ "<br>LastName:" + window.localStorage.getItem("lastname") + "<br>" + "<br>Address:" + window.localStorage.getItem("address") +"<br>"+ "<br>Apt:" + window.localStorage.getItem("apt") +"<br>" + "<br>City:" + window.localStorage.getItem("city") );
  return true;
  }
}

推荐答案

([id ='firstname'])。val();
var lname =
("[id='firstname']").val(); var lname=


([id ='lastname'])。val();
var _address =
("[id='lastname']").val(); var _address=


([id ='address'])。val();
var _apt =
("[id='address']").val(); var _apt=


这篇关于使用javascript验证无法在phonegap中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆