function judge(id,pwd){
if(id.value==null)
{
document.getElementById("tip").innerHTML="请输入账号";
}
else
{
document.getElementById("tip").innerHTML="请输入密码";
}
}
以上是函数部分。
Q1:
<form action="" method="post" name="register">
<input type="text" id="id" placeholder="请输入账号" class="form-control" style="margin-bottom: 5%;">
<input type="password" id="pwd" placeholder="请输入密码" class="form-control" style="margin-top: 5%; margin-bottom: 3%;">
<span class="tip" id="tip"></span>
<input type="submit" value="登录" class="button" onsubmit="judge(document.getElementById('id'),document.getElementById('pwd'))">
</form>
为什么不能实现元素处出现"请输入账号"的效果?
Q2:
<form action="" method="post" name="register">
<input type="text" id="id" placeholder="请输入账号" class="form-control" style="margin-bottom: 5%;">
<input type="password" id="pwd" placeholder="请输入密码" class="form-control" style="margin-top: 5%; margin-bottom: 3%;">
<span class="tip" id="tip"></span>
<!--以下为修改代码-->
<button class="button" onclick="judge(document.getElementById('id'),document.getElementById('pwd'))">登录</button>
</form>
这样能实现效果,但是页面会重新加载,效果一闪而过。为什么?如何调整?
Q3:
<form action="" method="post" name="register">
<input type="text" id="id" placeholder="请输入账号" class="form-control" style="margin-bottom: 5%;">
<input type="password" id="pwd" placeholder="请输入密码" class="form-control" style="margin-top: 5%; margin-bottom: 3%;">
<span class="tip" id="tip"></span>
<!--以下为修改代码-->
<button class="button" onclick="judge(id,pwd)">登录</button>
</form>
为什么效果同2?id名也能引用一个对象?
Q4:
<form action="" method="post" name="register">
<!--将id改为name-->
<input type="text" name="id" placeholder="请输入账号" class="form-control" style="margin-bottom: 5%;">
<input type="password" name="pwd" placeholder="请输入密码" class="form-control" style="margin-top: 5%; margin-bottom: 3%;">
<span class="tip" id="tip"></span>
<button class="button" onclick="judge(id,pwd)">登录</button>
</form>
为什么效果同上?难道name也能引用一个对象?
浮云间
临摹微笑
青春有我
相关分类