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在HTML文件中不工作_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery在HTML文件中不工作

Javascript jQuery在HTML文件中不工作,javascript,jquery,html,Javascript,Jquery,Html,我尝试了导入jQuery的多种变体,但都不起作用。当我运行它时,主体中的所有内容都会显示出来,但是jQuery函数不起作用。 这是我目前的代码: <!DOCTYPE html> <html> <head> <script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <

我尝试了导入jQuery的多种变体,但都不起作用。当我运行它时,主体中的所有内容都会显示出来,但是jQuery函数不起作用。 这是我目前的代码:

<!DOCTYPE html>
<html>
<head>

<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script type='text/javascript'>

    $(window).load(function(){
        $('select').on('change',function(){
            var value=$(this).val();
            var output='';
            for(var i=1;i<=value;i++)
            {
                output+='<div>Your Text</div>';   
            }
            $('#test').empty().append(output);
        });
    }); 

</script>

</head>

<body>
    <select>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="10">10</option>
    </select>

    <span id="test">
    </span>
</body>

</html>

$(窗口)。加载(函数(){
$('select')。在('change',function()上{
var值=$(this.val();
var输出=“”;
对于(var i=1;i执行以下步骤:-

复制jquery库代码()代码,并将其以相同的名称保存在当前工作目录中(
jquery.min.js
):-

现在使用以下代码:-

<!DOCTYPE html>
<html>
    <head>
        <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
        <meta content="utf-8" http-equiv="encoding"><!-- this is for removing character encoding error--> 

        <script type='text/javascript' src="jquery.min.js"></script><!-- see the change here -->
    </head>
    <body>
    <select>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="10">10</option>
    </select>
    <span id="test">
    </span>
</body>
</html>
<script type = "text/javascript">
    $(document).ready(function(){
        $('select').on('change',function(){
            var value=$(this).val();
            var output='';
            for(var i=1;i<=value;i++)
            {
                output+='<div>Your Text</div>';   
            }
            $('#test').html(output); //html will do everything(removing and then adding)
        });
    }); 
</script>

1.
2.
3.
10
$(文档).ready(函数(){
$('select')。在('change',function()上{
var值=$(this.val();
var输出=“”;

对于(var i=1;我的工作方式很好。控制台中会出现什么错误?请使用绝对URL,有时某些浏览器会阻止来自不可信源的内容,请使用:
https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
OP正在执行一个
$(窗口).load()
,无需担心浏览器的位置打开浏览器的开发工具(Chrome和FF中的F12)然后转到控制台选项卡并重新加载页面。然后查看显示的错误。@borkborkbork您是否使用任何web服务器来获取文件?似乎jQuery正在使用
file://
protocol加载刚刚尝试过,这是我的解决方案!我只需要在本地下载jQuery库