Created
March 26, 2013 07:59
-
-
Save neekey/5243780 to your computer and use it in GitHub Desktop.
让HTML和Javascript保持分离
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>title</title> | |
</head> | |
<body> | |
<form> | |
<input type="text" name="name" id="my-name" placeholder="输入您的姓名" /> | |
<button type="submit" id="submit-form">提交</button> | |
</form> | |
<script> | |
var myNameIpt = document.getElementById( 'my-name' ); | |
var submitBtn = document.getElementById( 'submit-form' ); | |
submitBtn.onclick = checkForm; | |
function checkForm(){ | |
var name = myNameIpt.value; | |
if( !name ){ | |
alert( '姓名不能为空'); | |
myNameIpt.focus(); | |
return false; | |
} | |
} | |
</script> | |
</body> | |
<html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment