通过ajax动态获取jQuery脚本和内容 [英] getting jQuery scripts and content through ajax dynamically

查看:119
本文介绍了通过ajax动态获取jQuery脚本和内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面加载一个文件树,其中包含实际页面的链接,以及子树和所有内容。但是,由于大文件夹创建巨大的文件,jQuery脚本隐藏文件夹将是非常棒的。有一个问题,因为树是通过ajax加载的,并且从来没有看起来一样,所以jQuery是一样的。我可以动态地生成jQuery,但是它不会加载任何通过ajax加载的javascript。特别不是事件。 (jQuery,onclick)

 < ul> 
< li>< b> www< / b> - 5个文件,14个目录,共1877 KB。
< ul>
< li>< b>管理< / b> - 4个文件,3个目录,共44 KB。
< ul>
< li>< b> Editera< / b> - 2个文件,共16 KB。
< ul>
< li>< a href =../../../ lh10fego / Admin / Editera / gastbok_edit.asp> gastbok_edit.asp< / a> - < a href =viewSource4.asp?page = lh10fego / www / Admin / Editera / gastbok_edit.asp>查看源< / a> - 1100字节,最后修改于2011-01-17 12:06:43。 < b取代;找到表名:< / b> Gastbok< /锂>
< li>< a href =../../../ lh10fego / Admin / Editera / Medlem_edit.asp> Medlem_edit.asp< / a> - < a href =viewSource4.asp?page = lh10fego / www / Admin / Editera / Medlem_edit.asp>查看源< / a> - 15671个字节,最后修改于2011-01-17 12:06:44。 < b取代;找到表名:< / b> Inlogg< /锂>
< / ul>
< / li>
< li>< b> Radera< / b> - 2个文件,共2 KB。
< ul>
< li>< a href =../../../ lh10fego / Admin / Radera / gastbok_radera.asp> gastbok_radera.asp< / a> - < a href =viewSource4.asp?page = lh10fego / www / Admin / Radera / gastbok_radera.asp>查看源< / a> - 813字节,最后修改于2011-01-17 12:06:45。 < b取代;找到表名:< / b> Gastbok< /锂>
< li>< a href =../../../ lh10fego / Admin / Radera / medlem_radera.asp> medlem_radera.asp< / a> - < a href =viewSource4.asp?page = lh10fego / www / Admin / Radera / medlem_radera.asp>查看源< / a> - 811字节,最后修改于2011-01-17 12:06:45。 < b取代;找到表名:< / b> Inlogg< /锂>
< / ul>
< / li>
< li>< b> Uppdatera< / b> - 2个文件,共2 KB。
< ul>

为大码编写,但有一个渲染页面及其中的项目的示例。我认为路径变量可以用作一个类,因此给路径中的所有项目都是同一个类。感谢您阅读我的真棒文本块。例如:../../lh10fego/Admin/Radera。愿意和/引起问题?可能。



任何人都可以给我一个jQuery代码,它的工作方式是它会隐藏/显示每个项目与类似myClassnomatter在哪里他们在页面?



还有一种通过ajax请求添加后激活该代码的方法。



注入的html,包括javascript最终在文档头部的div内。



编辑:我设法得到几乎所需的功能,但仍然没有通过ajax 。我使用这个关键字并隐藏所有与下面的特定类。现在的问题是,由于链接位于另一个链接中,所以您点击的链接和顶部的链接将触发,隐藏所有内容。



EDIT2: / p>

  set fs = CreateObject(Scripting.FileSystemObject)
set folder = fs.GetFolder(path)
currentfolder = path
fname =替换(folder.path,/,x)
fname =替换(fname,。,2)
fname = fname,:,5)'删除wierd字符并在中间添加asd
fname =替换(fname,\,3)',以避免搜索$ b $时的多个匹配b fname = Replace(fname,Right(fname,7),asd& right(fname,7))

'显示目标文件夹和信息。

Response.Write(< li onclick =$(this).find('li。& fname&').slideToggle();>< b>& folder.Name&< / b> - _
& folder.Files.Count&files,)
如果folder.SubFolders.Count> 0 then
Response.Write(folder.SubFolders.Count&directories,)
end if
Response.Write(Round(folder.Size / 1024)&KB total。 _
& vbCrLf)

现在的问题是,因为它被应用于嵌套每当我点击某个东西,我点击的一个和最高的li标签将隐藏的li标签。此外,我现在正在工作的这个测试是没有ajax只是让我的jQuery排序。

解决方案

十天后,我觉得我有一个独一无二:

 < HTML>< HEAD> 
< script src =./ jquery.jstype =text / javascript>< / script>
< script type =text / javascript>
函数jqueryAjax(url)
{
$ .ajax({
url:+ url,
cache:false,
dataType:script ,
success:function(html){
$(#content)。append(html);
}
});
}
< / script>
< / head>
< body>
< div id =controlstyle =border:1px solid green;>
< p>< a href =#onclick =jqueryAjax('htmljs.js');返回false> Ajax with Jquery(1.2.6)< / a>< / p> ;
< / div>
< div id =contentstyle =border:1px solid red; width:640px; height:480px; top:200px>< / div>
< / body>< / html>

坏消息是:错误控制台中出现错误消息,我无法删除。但它有效...


I've got a page which loads a file tree with links to the actual pages and such, with subtrees and everything. But since large folders create huge files, a jQuery script to hide folders would be awesome. There is a problem tho, since the tree is loaded through ajax, and never looks the same, nether does the jQuery. I can generate the jQuery dynamically, but it doesn't load any javascript which is loaded through ajax. Specially not events. (jQuery, onclick)

<ul>
<li><b>www</b> - 5 files, 14 directories, 1877 KB total.
<ul>
<li><b>Admin</b> - 4 files, 3 directories, 44 KB total.
<ul>
<li><b>Editera</b> - 2 files, 16 KB total.
<ul>
<li><a href="../../../lh10fego/Admin/Editera/gastbok_edit.asp">gastbok_edit.asp</a> - <a href="viewSource4.asp?page=lh10fego/www/Admin/Editera/gastbok_edit.asp"> View Source</a> - 1100 bytes, last modified on 2011-01-17 12:06:43.   <b> table names found:</b> Gastbok</li>
<li><a href="../../../lh10fego/Admin/Editera/Medlem_edit.asp">Medlem_edit.asp</a> - <a href="viewSource4.asp?page=lh10fego/www/Admin/Editera/Medlem_edit.asp"> View Source</a> - 15671 bytes, last modified on 2011-01-17 12:06:44.   <b> table names found:</b> Inlogg</li>
</ul>
</li>
<li><b>Radera</b> - 2 files, 2 KB total.
<ul>
<li><a href="../../../lh10fego/Admin/Radera/gastbok_radera.asp">gastbok_radera.asp</a> - <a href="viewSource4.asp?page=lh10fego/www/Admin/Radera/gastbok_radera.asp"> View Source</a> - 813 bytes, last modified on 2011-01-17 12:06:45.   <b> table names found:</b> Gastbok</li>
<li><a href="../../../lh10fego/Admin/Radera/medlem_radera.asp">medlem_radera.asp</a> - <a href="viewSource4.asp?page=lh10fego/www/Admin/Radera/medlem_radera.asp"> View Source</a> - 811 bytes, last modified on 2011-01-17 12:06:45.   <b> table names found:</b> Inlogg</li>
</ul>
</li>
<li><b>Uppdatera</b> - 2 files, 2 KB total.
<ul>

sry for the big code, but there is an example of a rendered page and the items in it. I thought that the path variable could be used as a class, therefore giving all items in a path the same class. Thank you for reading my awesome textblock. example: "../../lh10fego/Admin/Radera". Will . and / cause problems? Probably.

Can anyone give me an jQuery code which works in such a way that it will hide/show every item with a class like "myClass" nomatter where they are on the page?

And also a way to activate that code after being added through an ajax-request.

The injected html, including the javascript ends up inside a div in the head of the document.

EDIT: I managed to get almost the needed functionality, but still not through ajax. I used this-keyword and hidden all with the specific class beneath. The problem now is that since the link is inside another link, both the one you clicked and the one at the very top will trigger, hiding everything aswell.

EDIT2:

    set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)
    currentfolder = path
    fname = Replace(folder.path,"/","x")
fname = Replace(fname,".","2")
fname = Replace(fname,":","5")   'removing wierd chars and adding "asd" in middle
fname = Replace(fname,"\","3")   'to avoid multiple hits when searching
fname = Replace(fname,Right(fname,7),"asd" & Right(fname,7))

    'Display the target folder and info.

     Response.Write("<li onclick=""$(this).find('li." & fname & "').slideToggle();""><b>" & folder.Name & "</b> - " _
       & folder.Files.Count & " files, ")
     if folder.SubFolders.Count > 0 then
       Response.Write(folder.SubFolders.Count & " directories, ")
     end if
     Response.Write(Round(folder.Size / 1024) & " KB total." _
       & vbCrLf)

The problem right now is that since it's applied to nested li-tags whenever i click something, both the one i clicked and the highest li-tag will hide. Also, this test i'm working in right now is without ajax just to get my jQuery sorted.

解决方案

after ten days I think I've got a soloution:

<html><head>
    <script src="./jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        function jqueryAjax(url)
        {
            $.ajax({
              url: ""+url,
              cache: false,
              dataType: "script",
              success: function(html){
                $("#content").append(html);
              }
            });
        }
    </script>
</head>
<body>
    <div id="control" style="border: 1px solid green;">
        <p><a href="#" onclick="jqueryAjax('htmljs.js'); return false">Ajax with Jquery (1.2.6)</a></p>
    </div>
    <div id="content" style="border: 1px solid red; width: 640px; height: 480px; top: 200px"></div>
</body></html>

The bad news is: an error message comes up in the error console and I cannot remove those. But it works...

这篇关于通过ajax动态获取jQuery脚本和内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆