Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript的执行_Javascript_Html - Fatal编程技术网

JavaScript的执行

JavaScript的执行,javascript,html,Javascript,Html,你能帮我理解代码有什么问题,为什么我点击按钮时按钮不起作用吗。 我相信我错过了一些小部分,我找不到它 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Conditions</title> <link href="css/styles.css" rel="stylesheet"> <sc

你能帮我理解代码有什么问题,为什么我点击按钮时按钮不起作用吗。 我相信我错过了一些小部分,我找不到它

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Conditions</title>
    <link href="css/styles.css" rel="stylesheet">
    <script>
        function AgeCh 
    {
    var Age = prompt("Please enter your age here","from 4 to 100");

        if (Age >= 16) 
        {
    document.write("You are old enough to drive.");
        } 
        else if (Age >=21) 
        {
    document.write("You are old enough to drive and vote.");
        } 
        else if (Age >=65)
        {
    document.write("You are old enough to drive, vote and retire.");
        }
        else 
        {
            document.write ("thinks");
        }
}
    </script>
</head>

<body>


    <div class="classselector">

  <button type = "button" onclick="AgeCh()">Age Checker</button>

    </div>



</body>

</html>

条件
函数AgeCh
{
var Age=提示(“请在此处输入您的年龄”,“从4岁到100岁”);
如果(年龄>=16岁)
{
写下(“你已经足够大了,可以开车了。”);
} 
否则,如果(年龄>=21岁)
{
写下(“你已经足够大了,可以开车和投票了。”);
} 
否则,如果(年龄>=65岁)
{
写下(“你已经足够大了,可以开车、投票和退休了。”);
}
其他的
{
写文件(“思考”);
}
}
年龄检查器
我真的很感激你的帮助。我真的不知道为什么javascript在这里不起作用

您在AgeCh中缺少
()
。函数的定义应类似于
AgeCh()

更正代码:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Conditions</title>
    <link href="css/styles.css" rel="stylesheet">
    <script>
        function AgeCh() 
    {
    var Age = prompt("Please enter your age here","from 4 to 100");

        if (Age >= 16) 
        {
    document.write("You are old enough to drive.");
        } 
        else if (Age >=21) 
        {
    document.write("You are old enough to drive and vote.");
        } 
        else if (Age >=65)
        {
    document.write("You are old enough to drive, vote and retire.");
        }
        else 
        {
            document.write ("thinks");
        }
}
    </script>
</head>

<body>


    <div class="classselector">

  <button type = "button" onclick="AgeCh()">Age Checker</button>

    </div>



</body>

</html>

条件
函数AgeCh()
{
var Age=提示(“请在此处输入您的年龄”,“从4岁到100岁”);
如果(年龄>=16岁)
{
写下(“你已经足够大了,可以开车了。”);
} 
否则,如果(年龄>=21岁)
{
写下(“你已经足够大了,可以开车和投票了。”);
} 
否则,如果(年龄>=65岁)
{
写下(“你已经足够大了,可以开车、投票和退休了。”);
}
其他的
{
写文件(“思考”);
}
}
年龄检查器

似乎是定义函数时出错。我使用
let AgeCh=function(){}
重新定义了函数,这似乎让函数正常工作


函数文档:

是检查您的函数声明是否错误 就像

改为

function AgeCh()
{

a) “不起作用”几乎没有任何信息。你期待什么?你看到了什么?b) 您是否检查了开发人员工具控制台的错误?它们是什么?c) 不要使用
文档。除非你了解副作用,否则写
,也就是说,它会把你搞得一团糟。d)
函数AgeCh{
应该是
函数AgeCh(){
,如果输入年龄至少是16岁,那么所有条件都是“你已经足够大了,可以开车了。”。如果比较顺序是从较低的值到较高的值,则应按“小于”而不是“大于”进行比较。。
function AgeCh()
{