function myfunction(){
if (document.getElementById('name1').value!="liu"){
alert("用户名错误"); return false;}
else if(document.getElementById('password1').value!="123456") {
alert('密码错误');return false;}
else{alert('登录成功');}
}
if (document.getElementById('name1').value!="liu"){
alert("用户名错误"); return false;}
else if(document.getElementById('password1').value!="123456") {
alert('密码错误');return false;}
else{alert('登录成功');}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="textml; charset=utf-8" />
<title>swcss</title>
<style type="text/css">
.linear{
width:30%;
height:160px;
background:-webkit-gradient(linear, 0% 0%, 0% 100%,from(#FFF),to(#CCC));/*谷歌*/
opacity:0.8;
}
body{
background:url(8.jpg);
background-repeat:no-repeat;
background-size:cover;
}
</style>
</head>
<body>
<form >
<div class="linear" align="center" style="text-align:center; margin-left:34%;margin-top:20%;">
<table align="center" valign="middle" style="text-align:center; margin-top:15%; padding-top:10%;">
<tr>
<td>用户名</td>
<td><input type="text" id="name1" name="name"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" id="password1" name="password"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Log in" onclick="myfunction()" style=" background-color:#09F;font-size:22px;">
</td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
function myfunction(){
if (document.getElementById("name1").value!="liu"){
alert("用户名错误"); return false;}
if(document.getElementById("password1").value!="123456"){
alert('密码错误');return false;}
else{alert('登录成功');}
}
</script>
</body>
<html>
<input type="submit" value="Log in" onclick="return myfunction()" style=" background-color:#09F;font-size:22px;">
><input type="submit" value="Log in" onclick="return myfunction()" style=" background-color:#09F;font-size:22px;">
函数改成这样
function myfunction(){
if (document.getElementById("name1").value!="liu"){
alert("用户名错误"); return false;}
if(document.getElementById("password1").value!="123456"){
alert('密码错误');return false;}
else{alert('登录成功');}
return true;
}
onclick="return myfunction()"
return true;
是什么,加不加它有很大区别吗