jQuery文档的准备功能太长,我想导出其中的一部分

亚伯·凯

好的,这是我第一次问问题,尽管我已经使用该网站很长时间了。我似乎找不到我想要的东西。

我有一个文档就绪功能,其中的某些部分希望我可以“导出”,因此不需要在每一页上都重复这些内容。有点像ASP,包括页眉,页脚甚至是主容器。这可行吗?请看一下我的意思:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Some Title</title>
<link rel="styleSheet" href="somePath/myCssFile.css" type="text/css" media="screen" />
<script src="../somePath/jquery.min.js" type="text/javascript"></script>
<script src="../somePath/my_own_JS_stuff.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
    // this part is unique to THIS page

    $('#myUniqueDiv').delay(1000).fadeIn(500);
    $(document).attr("title", "MisterKay.com | " + someArray[parseInt(a) + parseInt(b)]);
    $('#myUniqueDiv').hover(function(){ 
        // some code here
    }, function(){
        // some more code here
    });

    // This part is repeated on all pages of the site.
    // I wish I could take this part out of here, put it in a file and just call the file, like a virtual file in ASP.
    // That way, if I make a modification, I could do it once for the entire site, instead for doing it for each page.
    // I cannot put it in a separate JS file either; for some reason it gives me an error.
    // My guess is this happens because this is INSIDE of the document-ready-function.
    // But I also cannot put it outside of the document-ready-function. 
    $('#someRepeatedDiv').cycle({ 
        fx:     'fade', 
        speed:  1000, 
        timeout:    3000
    });
    $('#someRepeatedInputBox').blur(function(){
        var sVal = $(this).val();
        if(sVal == ""){
            $(this).val(someArray[a]);
            $(this).css('color','#999');
        }
    });
    // End of repeated section of the document-ready-function
}); // End of document-ready-function
</script>
</head>
<body>
        <!-- #include virtual="header.html" -->
        <!-- #include virtual="main.html" -->
        <!-- #include virtual="footer.html" -->
</body>
</html>

如何将需要在每页上重复的部分放入某个外部文件,并仍由文档就绪功能读取?

再次感谢您的解答!

爱德华

您可以尝试jQuery $ .getScript():

Load a JavaScript file from the server using a GET HTTP request, then execute it.

例子:

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});

有关更多详细信息:http : //api.jquery.com/jquery.getscript/

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我有一个嵌套列表,想使用列表理解提取其中的一部分

具有合并功能的Firestore更新-如何覆盖文档的一部分

如何导出解构赋值的一部分?

我课程的String中的“&”符号不被视为其中的一部分

我需要合并 2 个查询,但需要对其中的一部分求和

我的向下滚动功能没有向下滚动到页面的同一部分 - jQuery

Excel在复制时弄乱了我的公式,如何停止停止更改其中一部分而不更改另一部分?

仅检索文档的一部分

我查询的哪一部分是错误的?UNNEST功能

N1QL查询,用于获取文档,其中期望字段是列表的一部分

从另一个子文档填充猫鼬的子文档,其中两个子文档都是主文档的一部分

我想让 Href 带我到另一个网页的一部分

我如何清除状态的一部分

我是僵尸网络的一部分吗?

Safari删除我的段落的一部分

jquery获取一部分ID

jQuery删除图像源的一部分

jQuery获得XML的一部分

javascript / jquery抓取URL的一部分

用jQuery更改链接的一部分

jQuery搜索单词的一部分

降价选择问题。按钮插入内容,但我希望选择其中一部分

MySQL:加入一个表,其中多行是条件的一部分

选择其中一栏的另一部分

我如何才能使对象仅在JAVA中某个功能的一部分中存在?

作为 dplyr 过滤功能的一部分,我如何遍历列表的元素并最终在 R 中打印差异?

VSCode查找和替换-查找实例,其中搜索表达式的一部分与条件匹配,而一部分与条件不匹配

在 PHP 中分解文件名以使用其中的一部分

如何捕获String表达式并仅替换其中一部分?