JQuery 与 will_paginate ajax 分页冲突
我按照 this 操作并让 AJAX 分页正常工作。但是,当我包含 JQuery 库时,它不起作用。我正在使用 jrails 插件,但这也没有帮助。有什么想法吗?谢谢 !
这是 JavaScript
document.observe("dom:loaded", function() {
var container = $(document.body)
if (container) {
var img = new Image
img.src = 'images/spinner.gif'
function createSpinner() {
return new Element('img', { src: img.src, 'class': 'spinner' })
}
container.observe('click', function(e) {
var el = e.element()
if (el.match('.pagination a')) {
el.up('.pagination').insert(createSpinner())
new Ajax.Request(el.href, { method: 'get' })
e.stop()
}
})
} })
编辑
这是我的实际代码,当我不包含 JQUERY 时它工作正常。 但我需要同时使用原型和 JQUERY。另外,当我单击其中一页时,我会得到这个
try {jQuery("#testing").html("\n <div class=\"pagination ajax\"> ......
I followed this and got the AJAX pagination to work. But, when I include the JQuery library, it doesn't work. I'm using the jrails plugin but that doesn't help either. Any ideas? Thanks !
Here's the javascript
document.observe("dom:loaded", function() {
var container = $(document.body)
if (container) {
var img = new Image
img.src = 'images/spinner.gif'
function createSpinner() {
return new Element('img', { src: img.src, 'class': 'spinner' })
}
container.observe('click', function(e) {
var el = e.element()
if (el.match('.pagination a')) {
el.up('.pagination').insert(createSpinner())
new Ajax.Request(el.href, { method: 'get' })
e.stop()
}
})
}
})
EDIT
This is my actual code and it works fine when I don't include JQUERY.
But I need to use both prototype and JQUERY. Also when I click on one of the page no.s I get this
try {jQuery("#testing").html("\n <div class=\"pagination ajax\"> ......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您包含 jquery 库时,它将假定所有 $ 调用都是对 jquery 的调用(而不是例如原型)。为了防止这种情况,请在拉入 jquery 对象后立即调用 noConflict 方法。请参阅 http://api .jquery.com/jQuery.noConflict/
当你这样做时, $ 调用将被 jQuery 忽略:它只会响应“jQuery”,即
When you include the jquery library, it will assume that all $ calls are calls to jquery (rather than prototype for example). To prevent this, call the method noConflict on your jquery object immediately after pulling it in. See http://api.jquery.com/jQuery.noConflict/
When you've done this, $ calls will be ignored by jQuery: it will only respond to "jQuery", ie