JavaScriptの例四(入力枠の数値フォーマットの検出)
1345 ワード
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title> </title>
</head>
<body>
<p> , </p>
<form action="http://localhost/index.jsp">
<input type="textarea" id="textbox">
<button type="submit" id="mybtn"> </button>
</form>
<script>
var textbox=document.forms[0].elements[0];
//
textbox.onfocus=function(){
if(textbox.style.backgroundColor != "red"){
textbox.style.backgroundColor="yellow";
}
}
//
textbox.onblur=function(event){
if(/[^\d]/.test(textbox.value)){
textbox.style.backgroundColor="red";
}else{
textbox.style.backgroundColor="";
}
}
//change
textbox.onchange=function(event){
if(/[^\d]/.test(textbox.value)){
textbox.style.backgroundColor="red";
}else{
textbox.style.backgroundColor="";
}
}
</script>
</body>
</html>