JavaScriptÖеÄÕýÔòÌæ»»
String.replace(regexp, replaceText); ÕâÊÇStringÀàÖеÄreplace·½·¨ÔÐÍ
replace·½·¨½ÓÊÜÁ½¸ö²ÎÊý:
regexp: ÕýÔò±í´ïʽ, ÓÃÀ´ÔÚ×Ö·û´®ÖÐËÑË÷µÄ¹æÔò.
replaceText: ÓÃÀ´Ìæ»»×Ö·û´®ÖÐÆ¥ÅäÕýÔò±í´ïʽµÄ×Ó´®µÄ×Ö·û´®
ÔÚJavaScriptÖÐ, Ö§³ÖÕýÔòÌæ»», ÕýÔòÌæ»»µÄ¹æÔòÈçÏÂ:
$$: ÔÒâ´òÓ¡Ò»¸ö$·ûºÅ
$&: Óë¹æÔòÆ¥ÅäµÄÕû¸ö×Ó´®
$`(´ó¼üÅÌ1ÅԱߵļü): Õû¸ö×Ö·û´®ÖÐ, Óë¹æÔòÆ¥ÅäµÄ×Ó´®Ö®Ç°µÄ²¿·Ö
$'(µ¥ÒýºÅ): Õû¸ö×Ö·û´®ÖÐ, Óë¹æÔòÆ¥ÅäµÄ×Ó´®Ö®ºóµÄ²¿·Ö
$n: $1, $2µÈ´Ó1-9µÄÊýÖµ, ´ú±íÕýÔòÆ¥ÅäµÃµ½µÄµÚn¸ö×Ó×éµÄÆ¥Åä×Ó´®
$nn: µÚ01-99¸ö×Ó×éµÄÆ¥Åä×Ó´®.
ÒÔ×Ö·û´®"abcdefg"ʹÓÃÕýÔò±í´ïʽ/(?:(bc)(de)(f))/½øÐÐÕýÔòÌ滻ΪÀý(?:)±íʾÊǷDz¶»ñ×Ó×é, ÊôÓÚÕýÔò±í´ïʽ·¶³ë, ÕâÀï²»×öÌÖÂÛ
ÔòÓÐ:
$&´ú±íbcdef
$`´ú±ía
$'´ú±íg
$1´ú±íbc
$2´ú±íde
$3´ú±íf
ÏÂÃæÊÇÒ»¸ö±È½ÏÍêÕûµÄÀý×Ó, ÔÚÀý×ÓÖÐΪÁË·½±ã²Ù×÷, ʹÓÃÁËjQuery, ¿ÉÒÔµ½jQuery¹Ù·½ÍøÕ¾ÏÂÔØ
http://jquery.com/
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavascriptÁ·Ï°-2-ÕýÔò±í´ïʽ</title>
<mce:script type="text/javascript" src="scripts/jquery-1.3.2.js" mce_src="scripts/jquery-1.3.2.js"></mce:script>
<mce:script type="text/javascript"><!--
$(function() {
var body = $('body');
function append(msg) {
return body.append($('<div>').text(msg));
}
function appendHtml(msg) {
return body.append($('<div>').html(msg));
}
function appendHr() {
return body.append($('<hr>'));
}
var re = /(https?):\/\/(\w+(?:\.\w+){2,})\/\?((\w+)=(\w+))/;
appendHtml("[prefix]http://www.google.com/?user=selfimpr[suffix].replace(re4, " +
"" +
"\"{" +
"url: '$&', " +
"prefix: '$`', " +
"suffix: '$'', " +
"protocal: '$1', " +
"server: '$2', " +
"queryString: '$3', " +
"argName: '$4', " +
"argValue: '$5'" +
"}\")");
appendHtml('<font color="red">' + "[prefi
Ïà¹ØÎĵµ£º
1. Ó¦Óà Array.prototype.joinʵÏÖ×Ö·ûºÏ²¢
·½·¨1.
String.prototype.times = function(n) {
return Array.prototype.join.call({length:n+1}, this);
};
"js".times(5) // => "jsjsjsjsjs"
·½·¨2.
var ArrayTest=new Array("HE","LL","O");
var hello = Array.prot ......
ÔÎÄ£º¡¶Speeding up JavaScript: Working with the DOM¡·
×÷Õߣº KeeKim Heng, Google Web Developer
ÔÚÎÒÃÇ¿ª·¢»¥ÁªÍø¸»Ó¦Óã¨RIA£©Ê±£¬ÎÒÃǾ³£Ð´Ò»Ð©javascript½Å±¾À´Ð޸ĻòÕßÔö¼ÓÒ³ÃæÔªËØ£¬ÕâЩ¹¤×÷×îÖÕÊÇDOM——»òÕß˵Îĵµ¶ÔÏóÄ£ÐÍ——À´Íê³ÉµÄ£¬¶øÎÒÃǵÄʵÏÖ·½Ê½»áÓ°Ïìµ½Ó¦ÓõÄÏìÓ¦Ëٶȡ£
DO ......
function addLoadEvent(fun) {
var oldonload = window.onload;
if(typeof(window.onload) != 'function') {
window.onload = fun;
} else {
window.onload = function() {
oldonload();
fun();
}
}
}
//function insertAfter(newElement, targentElement)
function insertAfter(insertedNode, ......
JavaScript¶¯Ì¬Ìí¼Óɾ³ý±í¸ñÐÐ(Ö§³ÖFireFox)
2006-08-16 12:47
¡¡¡¡Ð§¹ûͼÈçÏ£º
¡¡¡¡µã“Ìí¼Ó²ÎÓëÈË”°´Å¥¿ÉÒÔÌí¼ÓÒ»ÐУ¬Ã¿ÐкóÃ涼ÓÐÒ»¸öɾ³ý°´Å¥£¬¿ÉÒÔɾ³ýËùÔÚÐУ¬“Çå¿Õ”Ôòɾ³ýËùÓеÄÐС£
¡¡¡¡ÕâÖÖЧ¹ûÔÚÐèÒªÅúÁ¿Ìí¼ÓÊý¾ÝµÄʱºò·Ç³£ÓÐÓ㬿ÉÒÔÔÚ¿Í»§¶ËÌí¼ÓÍêÒ»ÅúÊý¾Ý£¬È»ºóͨ¹ýAJAXÒ»´ÎÌá½ ......
ÔÚjavascriptº¯ÊýÌåÄÚ£¬±êʶ·ûarguments¾ßÓÐÌØÊ⺬Òå¡£ËüÊǵ÷ÓöÔÏóµÄÒ»¸öÌØÊâÊôÐÔ£¬ÓÃÀ´ÒýÓÃArguments¶ÔÏó¡£Arugments¶ÔÏó¾ÍÏñÊý×飬עÒâÕâÀïÖ»ÊÇÏñ²¢²»Êǹþ¡£
javascriptº¯ÊýÌåÄÚ£¬argumentsÏñÊý×é(²¢²»ÊÇÕæµÄÊý×飬ÊÇÒ»¸öArguments¶ÔÏó£¬ÔÙ´ÎÇ¿µ÷)Ò»Ñù£¬ÓÐlengthÊôÐÔ£¬¿ÉÒÔ´ú±í´«¸øº¯ÊýµÄ²ÎÊýµÄ¸öÊý¡£
ÒýÓÃÒ»¸öÐÎʽ² ......