Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 - Fatal编程技术网

制作javascript文件

制作javascript文件,javascript,jquery,Javascript,Jquery,我想问一下是否可以将以下JavaScript代码合并到一个文件中 当我输入一个file.js时 $(document).ready(function(){$('#slider-with-blocks-1').royalSlider({arrowsNav:true,arrowsNavAutoHide:false,fadeinLoadedSlide:false,controlNavigationSpacing:0,controlNavigation:'

我想问一下是否可以将以下JavaScript代码合并到一个文件中

当我输入一个file.js时

$(document).ready(function(){$('#slider-with-blocks-1').royalSlider({arrowsNav:true,arrowsNavAutoHide:false,fadeinLoadedSlide:false,controlNavigationSpacing:0,controlNavigation:'bullets',imageScaleMode:'none',imageAlignCenter:false,blockLoop:true,loop:true,numImagesToPreload:6,transitionType:'fade',keyboardNavEnabled:true,block:{delay:400} })  });


将其存储在js文件中:

$(document).ready(function(){
    $('#slider-with-blocks-1').royalSlider(
        {arrowsNav:true,
         arrowsNavAutoHide:false,
         fadeinLoadedSlide:false,
         controlNavigationSpacing:0,
         controlNavigation:'bullets',
         imageScaleMode:'none',
         imageAlignCenter:false,
         blockLoop:true,
         loop:true,
         numImagesToPreload:6,
         transitionType:'fade',
         keyboardNavEnabled:true,
         block:{delay:400} });

    $('.credit ').append(' credit by <span></span>');
    $('.credit span').html('<a/>').attr('href:\\www.google.com').text('This is my link to google!');
    $('.credit span ').attr('id', 'credit');

    $("[role='navigation']").flexNav();

 });

$(window).load(function() {
    if (!document.getElementById('credit') || document.getElementById('credit').href != "http://www.google.com/") {
        alert('Kreditnya jangan diilangin sob!');
    }
)};
并称之为:

<script type="text/javascript" src="myFile.js"></script>

最好取消代码的scape,并正确缩进源代码:以使所有代码更具可读性。

是否尝试将代码填充到一个文件中?请取消引用@搅拌机是的,我想把它做成一个文件。@SodiycKurniawan:但是你试过了吗?只需将所有这些代码块粘贴到一个文件中。它应该可以工作。非常感谢您的帮助,但是为什么在我尝试不运行它之后呢?@Sodiyc Kurniawan:在调用myFile.js之前,确保您已经加载了jquery文件。然后,您可能需要从}更改myFile.js中的最后一行;到};
window.onload = function() {
    if (!document.getElementById('credit') || document.getElementById('credit').href != "http://www.google.com/") {
        alert('Kreditnya jangan diilangin sob!');
    }
};
$(document).ready(function(){
    $('#slider-with-blocks-1').royalSlider(
        {arrowsNav:true,
         arrowsNavAutoHide:false,
         fadeinLoadedSlide:false,
         controlNavigationSpacing:0,
         controlNavigation:'bullets',
         imageScaleMode:'none',
         imageAlignCenter:false,
         blockLoop:true,
         loop:true,
         numImagesToPreload:6,
         transitionType:'fade',
         keyboardNavEnabled:true,
         block:{delay:400} });

    $('.credit ').append(' credit by &lt;span&gt;&lt;/span&gt;');
    $('.credit span').html('<a/>').attr('href:\\www.google.com').text('This is my link to google!');
    $('.credit span ').attr('id', 'credit');

    $("[role='navigation']").flexNav();

 });

$(window).load(function() {
    if (!document.getElementById('credit') || document.getElementById('credit').href != "http://www.google.com/") {
        alert('Kreditnya jangan diilangin sob!');
    }
)};
<script type="text/javascript" src="myFile.js"></script>