-1

我正在使用 jquery 来缩放图像,它在测试html上运行良好

但是它显示错误,当我尝试在实时网站中实现它时看起来像冲突错误,因为其他 js 也调用它,它显示以下错误

Uncaught TypeError: Object #<HTMLDocument> has no method 'ready'* 在第 1 行base.js

我尝试了下面的代码以避免冲突,但它不起作用看起来我错过了一些东西

jquery.noconflict();
$(document).ready(on_ready);
function on_ready() {
$('#search').defaultVal('search here...');
$('#comment').defaultVal('your comment here...');
$('#message').defaultVal('your message here...');
.....

base.js文件可以在下面提到的链接上看到

http://techchef.co/devTest/test/base.js

4

4 回答 4

2
jQuery.noConflict();
// cannot use '$' because of .noConflict()
// now the '$'-sign is free for other libraries e.b. MooTools...
// ...that's what noConflict does

// try using 'jQuery' instead of '$' here
jQuery(document).ready(function() {
    jQuery('.selector').click(function() {
        // and so on
    });
});

// or an other solution looks like this

(function($) {
    $(function() {
        // more code using $ as alias to jQuery
    });
})(jQuery)

// in your case try

jQuery(document).ready(function() {
    // the code you have in your on_ready-function
});

// or

jQuery(document).ready(function() {
    on_ready();
});
function on_ready() {
    // your on_ready-function
}

更多信息

于 2013-01-14T14:16:02.870 回答
0
var j = jQuery.noConflict();
// Do something with jQuery
j("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';

有关详细信息,请参阅此文档。

于 2013-01-14T14:16:26.000 回答
0

当我尝试像下面那样执行此操作时,它显示错误,并且在我调用它的页面上没有检测到函数调用

jQuery.noConflict() 
jQuery(document).ready(function($)
{ 
function on_ready() { $('#search').defaultVal('search here...');     
$('#comment').defaultVal('your comment here...'); 
$('#message').defaultVal('your message here...'); }); 

})

实际上,base.js 默认调用 on_ready 函数,如下所示

$(document).ready(on_ready); 
function on_ready() {
 $('#search').defaultVal('search here...');
 $('#comment').defaultVal('your comment here...');
 $('#message').defaultVal('your message here...'); 
于 2013-01-14T17:52:53.087 回答
0

我刚刚通过替换 in 解决了$这个jQuery问题base.js

它对我有用。希望能帮助到你。

于 2014-03-08T06:14:08.390 回答