Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.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_Jquery_Function_Call_Var - Fatal编程技术网

Javascript 字符串数组在调用后仍为空

Javascript 字符串数组在调用后仍为空,javascript,jquery,function,call,var,Javascript,Jquery,Function,Call,Var,从文件hfunc.js调用此函数时,varvid在我的DOM中显示为空。(我已经用警报(vid.length)检查过了): 我想使用document.write(vid[0])显示iframe p、 s:我很确定我把$(document.ready)搞砸了。jQuery document.ready函数应该这样描述: $(document).ready(function() { for (var n=0; n<1; n++) vid[0] = '<ifr

从文件
hfunc.js
调用此函数时,var
vid
在我的DOM中显示为空。(我已经用
警报(vid.length)
检查过了):

我想使用
document.write(vid[0])
显示iframe


p、 s:我很确定我把
$(document.ready)搞砸了。

jQuery document.ready函数应该这样描述:

$(document).ready(function() 
{  
    for (var n=0; n<1; n++)
        vid[0] = '<iframe width="560" height="315" src="https://www.youtube.com/embed/0xpAqxH2Kzw" frameborder="0" allowfullscreen></iframe>';
});
$(文档).ready(函数()
{  
对于(var n=0;n您可以尝试:

$(document).ready(function () {
    function wfiller() {
        for (var n = 0; n < 1; n++)
            vid[0] = '<iframe width="560" height="315" src="https://www.youtube.com/embed/0xpAqxH2Kzw" frameborder="0" allowfullscreen></iframe>';
    }
    wfiller();
    document.write(vid[0]);
});
$(文档).ready(函数(){
函数wfiller(){
对于(var n=0;n<1;n++)
vid[0]='';
}
wfiller();
文件写入(vid[0]);
});

您的document.ready很好,但脚本标记错误,而不是

<script>src="https://code.jquery.com/jquery-1.9.1.min.js"</script>
<script>src="hfunc.js"</script>
src=”https://code.jquery.com/jquery-1.9.1.min.js"
src=“hfunc.js”
试一试



Your document.ready函数正确。您的
script
标记格式也不正确。在HTML5中,是默认类型,因此不需要包含它。
$(document).ready(function () {
    function wfiller() {
        for (var n = 0; n < 1; n++)
            vid[0] = '<iframe width="560" height="315" src="https://www.youtube.com/embed/0xpAqxH2Kzw" frameborder="0" allowfullscreen></iframe>';
    }
    wfiller();
    document.write(vid[0]);
});
<script>src="https://code.jquery.com/jquery-1.9.1.min.js"</script>
<script>src="hfunc.js"</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="hfunc.js" type="text/javascript"></script>