日期:2014-05-16  浏览次数:20433 次

怎么用js 传递参数 到php文件
本帖最后由 xcleml 于 2014-03-20 22:12:46 编辑
刚学习php
写了个登陆页 在登陆页中 用js写了判断帐号密码是否空提示的代码 现在想要把输入的帐号密码传递到php验证页面中 不知道应该怎么写了 请大家指点 

这是代码
<script>
   window.onload=function()
    {
     var oUsername=document.getElementById('username');
        var oPassword=document.getElementById('password');
        var oBtn=document.getElementById('btn');
var oerr=document.getElementById('err');

        oUsername.focus();
  oBtn.onclick=function()
{
if(oUsername.value=='')
{
oerr.style.display='block';
oUsername.focus();
}
else if(oPassword.value=='')
{
oerr.style.display='block';
oPassword.focus();
}
else if(oerr.style.display='block')
{oerr.style.display='none';}


}
    }
</script>

<div id="log">
<div class="float"><img src="imger/login.png" /></div>

    <div class="login float">
     <div><div id="err">帐号或密码不能为空!</div></div>
        <div class="font20">帐 号</div>
        <div ><input id="username" class="texts" type="text" title="请输入帐号" name="username"/></div>
        <div class="font20">密 码</div>
        <div><input id="password" class="texts" type="password" title="请输入密码" name="password"/></div>
        <div><input id="btn" class="submit" type="submit" value="登陆"  onMouseOver="this.className='submint1'" onMouseOut="this.className='submit'"></input></div>
    </div>

</div>
------解决方案--------------------
无刷新验证的话,搜索ajax.
跳转到php端验证的话,直接提交表单即可。
------解决方案--------------------
不会啊,先进行js验证,再传到php验证嘛。
------解决方案--------------------
引用:
使用form 后 直接就传递至php验证页面了
还是我写错了

<form action="" method="get" onsubmit="return check();"></form>
function check(){
        //验证成功return true;失败return false;
}
------解决方案--------------------
贴出代码看看