<form ......onsubmit="return loginclick()> #必要
...
...
<script type="text/javascript">
function loginclick(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
if (username == '' || password == '') {
alert('填入信息!!');
return false;#必要
}
}
</script>
当然,也可以直接加required属性(html5)