当数据来自服务器端时,ThickBox 不工作
我正在使用 jQuery 厚框在模式对话框中显示 aspx 页面 这在我的页面中运行良好。在我的页面中,我有一些链接,当我单击这些链接时,使用 jQuery 的 Load 方法,我从服务器页面获取一些数据并将其加载到其中。(我获取的数据是一个网格,其中包含一些图像)。我的问题是,当我的厚盒在我的页面中进行硬编码时,它工作正常,但是当我从服务器获取它并加载到 div 时,它不起作用,而是在模式对话框中显示新页面,它重定向浏览器以加载该页面。
我在第一页中硬编码了这一行
<a class='thickbox' href='../Home/CostMetrics.aspx?Model=6&KeepThis=true&TB_iframe=true&height=300&width=850'>modal thick box link</a>
时,我从服务器生成此标记。
,当我将数据从服务器加载到 div 模态厚框链接
两者都是相同的。但是我的灯箱无法工作。有什么想法可以解决这个问题吗?
我在我的第一页中包含了厚盒 CSS 和 js。填充 div 的服务器页面返回这样的数据
<div><div><img src='abc.jpg' /> <a class="thickbox" href="../Home/CostMetrics.aspx?Model=5&KeepThis=true&TB_iframe=true&height=300&width=850">modal thick box link</a></div></div>
提前致谢
I m using jQuery thick box to show an aspx page in a modal dialog
This works fine in my page.In my page,I have some links on which when i click,using jQuery's Load method,I am getting some data from the server page and loading into it.(the data i m getting is a grid which contains some images).My problem is that my thickbox is working fine when it is hardcoded in my page,But when i am taking it from server and loading to a div,Its not working,Instead,of showing the new page in modal dialog,its redirecting the browser to load that page.
I hard coded this line in my first page
<a class='thickbox' href='../Home/CostMetrics.aspx?Model=6&KeepThis=true&TB_iframe=true&height=300&width=850'>modal thick box link</a>
and i am generating this tage from server when i load data from server to the div
<a class="thickbox" href="../Home/CostMetrics.aspx?Model=5&KeepThis=true&TB_iframe=true&height=300&width=850">modal thick box link</a>
Both are same.But my lightbox is not working.Any Ideas to solve this ?
I have included the thickbox CSS and js in my first page.My server page which fills the div is return data like this
<div><div><img src='abc.jpg' /> <a class="thickbox" href="../Home/CostMetrics.aspx?Model=5&KeepThis=true&TB_iframe=true&height=300&width=850">modal thick box link</a></div></div>
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了类似的问题 - 厚盒在页面中加载的数据上工作正常 - 但是当您返回动态内容(使用 jQuery Ajax 命令)“页面加载后”时 - 新数据中包含的链接将打不开厚盒...
我的解决方案:
Thickbox 在 Thickbox.js 文件中调用“tb_init”函数 - 该函数仅在页面加载时执行一次...您需要再次调用“tb_init”函数INSIDE执行新动态服务器内容的 jQuery 函数!
通过以下三行调用“tb_init”(您可以在“thickbox.js”文件的顶部找到这些行):
作为示例 - 这是我如何让 Thickbox 处理使用 jQuery 动态生成的内容的代码片段Ajax 命令(我认为它类似于您使用的 jQuery 的“加载”方法!?)...
这就是我的做法(我是 jQuery 新手),它可能不是最好的解决方案,但试用&amp; 错误引导我使用这个方法!
希望有帮助吗?
I had a similar problem - thickbox works fine on data that loads in page - but when you return dynamic content (using jQuery Ajax command) 'after the page has loaded' - links contained in that new data would not open thickbox...
My Solution:
Thickbox calls the "tb_init" function inside the thickbox.js file - which is only executed once, on page load... you need to call the "tb_init" function again INSIDE your jQuery function that executes the new dynamic server content!
Call the 'tb_init' by the following three lines (you can find these lines at top of "thickbox.js" file):
As an example - this is a code snippet of how i got thickbox working on content i dynamically generated using the jQuery Ajax command (which i think is similar to jQuery's 'Load' method that you use!?)...
This is how I did it (im new to jQuery), its probably not the best solution, but trial & error lead me to this method!
Hope that helps?
与 Sergey 所说的不同的是,在 .js 中的某个位置使用 jQuery 的 .live() 函数:
假设动态添加的链接的 ID 以“my_thick_...”开头
A variation from what Sergey says, is using jQuery's .live() function, somewhere in your .js:
assuming the IDs of your dynamically-added links started with 'my_thick_...'
据我记得,ThickBox 是在 DOM 准备就绪时初始化的(在 jQuery 的就绪事件上)。 在此初始化过程中,它会将默认的单击处理程序替换为显示模态的处理程序。 当您使用 jQuery 的 Load 方法加载数据时,没有这样的初始化。 为了解决这个问题,您应该在将新 html 插入到这个新 html 的页面中后手动初始化 ThickBox。 或者你也可以在所有元素上重新初始化 ThickBox(在将新的 html 插入 dom 后),这可以工作,但这不是最佳解决方案:
As far as I remember ThickBox is initialized when DOM is ready (on ready event of jQuery). During this initialization it replaces default click handler with one which will show you modal. When you use jQuery's Load method to load data there are no such initialization. In order to fix this you should manually initialize ThickBox after inserting new html into page on this new html. Or you also can reinit ThickBox on all elements (after you insert new html into dom), this will work but this is not optimal solution:
您可以将 Thickbox.js 中的原始 tb_init 函数代码替换为以下代码:
或者您可以将此函数作为普通 JS 函数放置在 html 页面的头部标记内。 它将使其能够很好地处理外部数据加载。
You can replace original tb_init function code inside thickbox.js to this one:
Or you can just place this function in the head of your html page inside tag as a normal JS function. It will make this work well with external data loads.