jquery写起来真的很简单,连我这刚接触jquery不久的新人都能很快用它码出大段的javascript。唯一的坏处是代码里充斥了大量的$。既然写javascript如此简单,那么用jquery+greasemonkey插件同时干活怎么样呢?
这里是一段提醒jquery已经载入的脚本,为了避免和页面上原有的代码冲突,得运行$.noConflict().
PLAIN TEXT
CODE:
// All your GM code must be inside this function
function letsJQuery() {
//make sure there is no conflict between jQuery and other libraries
$.noConflict()
//notify that jQuery is running...
$('<div>jQuery is running!</div>')
.css({padding: '10px', background: '#ffc', position: 'absolute',top: '0', width: '100%'})
.prependTo('body')
.fadeIn('fast')
.animate({opacity: 1.0}, 300)
.fadeOut('fast', function() {
$(this).remove();
[...]