<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>成绩查询</title> <script type="text/javascript"> function aa() { var num = document.getElementById("con").value; if(num>=60) alert("JavaScript考核通过!"); }else { alert("哈哈哈哈你并没有通过考核!") } } </script> </head> <body> <form> <label> <a style="font-family:Microsoft Yahei">成绩:</a> </label> <input type="text" id="con"/> <input type="button" value="查询" onclick="aa()"/> </form> </body> </html>
我输入之后 按了按键没有弹出alert
第一个错误://你右括号用了中文格式
var num = document.getElementById("con").value;
第二个错误:少了左{
if(num>=60)
第三个错误:少了分号
alert("哈哈哈哈你并没有通过考核!")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>成绩查询</title> <script type="text/javascript"> function aa() { var num = document.getElementById("con").value; if(num>=60){ alert("JavaScript考核通过!"); }else { alert("哈哈哈哈你并没有通过考核!") } } </script> </head> <body> <form> <label> <a style="font-family:Microsoft Yahei">成绩:</a> </label> <input type="text" id="con"/> <input type="button" value="查询" onclick="aa()"/> </form> </body> </html>
获取他的value
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>成绩查询</title> <script type="text/javascript"> function aa(){ var num = document.getElementById("con").value; if(num>=60){ alert("JavaScript考核通过!"); }else{ alert("哈哈哈哈你并没有通过考核!") } } </script> </head> <body> <form> <label> <a style="font-family:Microsoft Yahei">成绩:</a> </label> <input type="text" id="con"/> <input type="button" value="查询" onclick="aa()"/> </form> </body> </html>
试试这个,仔细对比下,你就知道哪儿错了
代码if(num>=60)后面少了一个 “{”