3tests.html
<!DOCTYPE html>
<html>
<head>
<title>三个练习答案</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function check() {
var text1EleValue = document.getElementById("text1").value;
if(text1EleValue.length==0) {
alert("长度不能为0!");
} else if(text1EleValue.charAt(0)=="a"||text1EleValue.charAt(0)=="A") {
alert("账号开头不能为A或a!");
} else {
alert("账号验证通过!");
}
}
function changepicture1() {
var img1 = document.getElementById("img");
img1.src="197512309156.jpg";
}
function changepicture2(){
var img2=document.getElementById("img");
img2.attributes["src"].nodeValue="197512569446.jpg";
}
function checkInt(){
var var_text2=document.getElementById("text2").value;
if(!parseFloat(var_text2)){
alert("请输入数字!");
}
else if(var_text2%1==0){
alert("输入为整数!");
}
else{
alert("不能输入浮点数!");
}
}
</script>
</head>
<body>
<input type="text" placeholder="请输入账号" id="text1">
<button onclick="check()">验证</button>
<br>
<button id="button1" onclick="changepicture1()">通过src属性切换图片1</button>
<br>
<button id="button2" onclick="changepicture2()">通过属性节点切换图片1</button>
<br>
<img alt="WOW" src="197512569446.jpg" id="img" style="width: 33%;">
<br>
<input type="text" placeholder="请输入" id="text2">
<button id="button3"onclick="checkInt()">检查是否为整数</button>
</body>
</html>