JavaScript 荧光笔v1.0

/*
**************************************
* String.highlight v1.0              *
* Autor: Carlos R. L. Rodrigues      *
**************************************
*/
String.prototype.highlight = function(f, c, i){
    var r = this, t = /([(){}|*+?.,^$\[\]\\])/g, i = !i ? "i" : "", rf = function(t, i){
        return r.lastIndexOf("<", i) > r.lastIndexOf(">", i) ? t : c(t, p);
    };
    for(var p = -1, l = (f = f instanceof Array ? f : [f]).length; ++p < l;)
        r = r.replace(new RegExp(f[p].replace(t, "\\\$1"), "gm" + i), rf);
    return r;
}

JavaScript 鼠标事件

/*-----------------------------------------------------------------------------
 * Mouse Event
 *  Example Source
	Event.Mouse.right(window, function (e) {
		alert(Event.pointerX(e) + ', ' + Event.pointerY(e));
	});
	Event.Mouse.wheel(window, function (e, roll) {
		alert(roll);
	});
 *  Event Observer Sample
	Event.observe = function (element, name, observer, useCapture) {
		useCapture = useCapture || false;
		// Start Remodel
		name = (name == 'keypress' && (navigator.appVersion.match(/Konqueror|Safari|KHTML/) || window.attachEvent)) ? 'keydown' : (name == 'mousewheel' && !window.attachEvent) ? 'DOMMouseScroll' : name;
		// End Remodel
		if (element.addEventListener)
			element.addEventListener(name, observer, useCapture);
		else if (element.attachEvent)
			element.attachEvent('on' + name, observer);
	}
 *-------------------------------------------------------------------------- */

var Mouse = {
	left: function (element, func) {
		Event.observe(element, 'click', func);
	},
	doubleleft: function (element, func) {
		Event.observe(element, 'dblclick', func);
	},
	right: function (element, func) {
		Event.observe(element, 'contextmenu', function (e) {
			func.apply(this, [e]);
			return false;
		})
	},
	wheel: function (element, func) {
		Event.observe(element, 'mousewheel', function (e) {
			func.apply(this, [e, (e.wheelDelta) ? e.wheelDelta / -120 : e.detail / 3]);
			Event.stop(e);
		});
	}
}

JavaScript 褪色幻灯片放映

<!-- THREE STEPS TO INSTALL FADING SLIDE SHOW:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the onLoad event handler into the BODY tag
  3.  Put the last coding into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  CodeLifter.com (support@codelifter.com) -->
<!-- Web Site:  http://www.codelifter.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000;
// Duration of crossfade (seconds)
var crossFadeDuration = 3;
// Specify the image files
var Pic = new Array();
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = '1.jpg'
Pic[1] = '2.jpg'
Pic[2] = '3.jpg'
Pic[3] = '4.jpg'
Pic[4] = '5.jpg'

// do not edit anything below this line
var t;
var j = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++) {
preLoad[i] = new Image();
preLoad[i].src = Pic[i];
}
function runSlideShow() {
if (document.all) {
document.images.SlideShow.style.filter="blendTrans(duration=2)";
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
document.images.SlideShow.filters.blendTrans.Apply();
}
document.images.SlideShow.src = preLoad[j].src;
if (document.all) {
document.images.SlideShow.filters.blendTrans.Play();
}
j = j + 1;
if (j > (p - 1)) j = 0;
t = setTimeout('runSlideShow()', slideShowSpeed);
}
//  End -->
</script>

</HEAD>

<!-- STEP TWO: Insert the onLoad event handler into your BODY tag  -->

<BODY onLoad="runSlideShow()">

<!-- STEP THREE: Copy this code into the BODY of your HTML document  -->

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="VU" height=150 width=150>
<img src="1.jpg" name='SlideShow' width=150 height=150>
</td>
</tr>
</table>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size:  2.13 KB -->

JavaScript 在Firefox和Internet Explorer中关闭窗口

<a href=\"javascript:window.open('','_parent','');window.close();\">Close Window</a>

JavaScript 在新窗口中打开外部链接

function handleExternalLinks() { // function makes sure that external links open in new window
	var hostName = window.location.hostname;
	var links = document.getElementsByTagName("a");
	for(var i = 0; i < links.length; i++) {
		if(links[i].href.indexOf(hostName) == -1) {
			var curTitle = (links[i].getAttribute("title")) ? links[i].getAttribute("title") + " - ": "";
			links[i].setAttribute("target", "_blank");
			links[i].setAttribute("title",  curTitle + "opens in new window");
		}
	}
}

handleExternalLinks(); // Call the function

JavaScript jQuery简单风格切换器

/** @id sipleSwitcher
* @classDescription Very simple style switcher using jQuery
*/
$(document).ready(function(){
	$('#styleSwitch .button').bind('click', function(){
		$('body').removeClass();//remove all the other classes
		$('#styleSwitch .button').removeClass('selected');
		$(this).addClass('selected');
		switch(this.id){
			case 'style1':
				$('body').addClass('style1');
				break;
			case 'style2':
				$('body').addClass('style2');
				break;
			case 'style3':
				$('body').addClass('style3');
				break;
		}
		return false;
	});
});

JavaScript JQuery:通用浏览器嗅探

//A. Target Safari
if( $.browser.safari ) $("#menu li a").css("padding", "1em 1.2em" );

//B. Target anything above IE6
if ($.browser.msie && $.browser.version > 6 ) $("#menu li a").css("padding", "1em 1.8em" );

//C. Target IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) $("#menu li a").css("padding", "1em 1.8em" );

//D. Target Firefox 2 and above
if ($.browser.mozilla && $.browser.version >= "1.8" ) $("#menu li a").css("padding", "1em 1.8em" );

JavaScript CSS浏览器选择器

/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

JavaScript JQuery - 获取匹配元素的总数

/*
 * Jquery (http://www.jquery.com)
 * size()
 * 
 * Returns the number of matched elements.
 */

$('element').size();

JavaScript [jQuery] StripTables

function stripTables(){
     // select all table elements, select all tr elements and apply the css { background : color }
     $('table').find("tr:odd").css({ background : "#f6f6f6" });
}