JavaScript入门之验证输入,对代码进行拆行

来源:互联网 发布:java cp 目录结构 编辑:程序博客网 时间:2024/05/18 02:17

函数   isNaN()   如果输入的不是数字   结果为true      如果输入的是数字  结果为flase

<html><body><h1>JavaScript</h1><p>请输入数字。如果输入值不是数字,浏览器会弹出提示框</p><input id = "demo" type = "text"><script>function myFunction(){var x = document.getElementById("demo").value;if (x == "" || isNaN(x)){alert("Not Numeric");}else{alert("Is Numeric");}}</script><button type = "button" onclick = "myFunction()">测试</button></body></html>

对代码进行拆行

可以用反斜杠对代码进行换行

document.write("Hello\world");




0 0
原创粉丝点击