Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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 jQuery对象内的提示函数不起作用_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery对象内的提示函数不起作用

Javascript jQuery对象内的提示函数不起作用,javascript,jquery,html,Javascript,Jquery,Html,如果我在这里说了些愚蠢的话,请原谅,我在jQuery有点不在行。我正在处理HTML/jQuery中的一个按钮,该按钮应该在单击时触发一个提示,然后返回另一个数字。问题是当我点击按钮时,提示不会触发 JavaScript: $(document).ready(function() { $('#Progress-Button').click(function() { var question = prompt("Enter number of hours worked:",

如果我在这里说了些愚蠢的话,请原谅,我在jQuery有点不在行。我正在处理HTML/jQuery中的一个按钮,该按钮应该在单击时触发一个提示,然后返回另一个数字。问题是当我点击按钮时,提示不会触发

JavaScript:

$(document).ready(function() {
    $('#Progress-Button').click(function() {
        var question = prompt("Enter number of hours worked:", "Enter here");
        if (isNaN(Number(question)) === false) {
            var width = question * 10;
            return width;
        } else {
          question = prompt("That is not a number; Enter the number of hours worked.", "Enter here");
        }
    )
})
HTML:


伊恩试验
点击我

您的
else
块缺少一个大括号,一些分号也缺少。试试这个:

$(文档).ready(函数(){
$(“#进度按钮”)。单击(函数(){
var问题=提示(“输入工作小时数:”,“在此处输入”);
如果(isNaN(数字(问题))==错误){
变量宽度=问题*10;
警报(宽度);
返回宽度;
}否则{
问题=提示(“这不是一个数字;输入工作小时数。”,“在此处输入”);
}
});
});

点击我
您应该使用:

jQuery(document).ready(function($) {
   enter code here
不是这个

$(document).ready(function() {
enter code here

看起来您的HTML中有一些错误,可能是这些错误造成的。
元素应位于
的内部。
都应在
范围内:


伊恩试验
点击我

您的代码运行平稳,唯一的问题是在执行else后没有正确关闭

}))

请尝试下面的代码

$(document).ready(function() {
  $('#Progress-Button').click(function() {
    var question = prompt("Enter number of hours worked:", "Enter here");
    if (isNaN(Number(question)) === false) {
      var width = question * 10;
      return width;
    } else {
      question = prompt("That is not a number; Enter the number of hours worked.", "Enter here");
    }
  });
})

是否记录了任何错误?我还没有检查。我现在就这么做,它给出了一个
引用错误:找不到变量:$
。我包含了来自google的用于jQuery的CDN。您缺少一个
}
来关闭
单击
方法调用中的回调函数。您的问题可能正是由于这个打字错误。我希望您看到这样一个错误:“未捕获的SyntaxError:意外令牌”问题得到解决!我使用的是过时的jQuery版本!大家好!有关HTML文档结构的更多详细信息,请查看以下内容。
<html>
    <head>
        <title>Ian TEST</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="index.js"></script>
        <link rel="stylesheet" href="index.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">    </script>
    </head>
    <body>
        <div id="main">
            <div id="Progress-BG"></div>
            <div id="Progress-Bar"></div>
            <button id="Progress-Button">Click Me</button>
        </div> 
    </body>
</html>
$(document).ready(function() {
  $('#Progress-Button').click(function() {
    var question = prompt("Enter number of hours worked:", "Enter here");
    if (isNaN(Number(question)) === false) {
      var width = question * 10;
      return width;
    } else {
      question = prompt("That is not a number; Enter the number of hours worked.", "Enter here");
    }
  });
})