Javascript »ñÈ¡Ò³ÃæÉÏÑ¡ÖеÄÎÄ×Ö
IE¿ÉÒÔµ÷Óãº
<script type="text/javascript">
// ˵Ã÷£º»ñÈ¡Ò³ÃæÉÏÑ¡ÖеÄÎÄ×Ö
// ÕûÀí£ºhttp://www.CodeBit.cn
function getSelectedText() {
if (window.getSelection) {
// This technique is the most likely to be standardized.
// getSelection() returns a Selection object, which we do not document.
return window.getSelection().toString();
}
else if (document.getSelection) {
// This is an older, simpler technique that returns a string
return document.getSelection();
}
else if (document.selection) {
// This is the IE-specific technique.
// We do not document the IE selection property or TextRange objects.
return document.selection.createRange().text;
}
}
</script>
ÔÚ FireFox Ï»ñÈ¡ input »òÕß textarea ÖÐÑ¡ÖеÄÎÄ×Ö£¬¿ÉÒÔÓÃÏÂÃæµÄ·½·¨£º
<script type="text/javascript">
// ˵Ã÷£ºFireFox Ï»ñÈ¡ input »òÕß textarea ÖÐÑ¡ÖеÄÎÄ×Ö
// ÕûÀí£ºhttp://www.codebit.cn
function getTextFieldSelection(e) {
if (e.selectionStart != undefined && e.selectionEnd != undefined) {
var start = e.selectionStart;
var end = e.selectionEnd;
return e.value.substring(start, end);
}
else return ""; // Not supported on this browser
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD
Ïà¹ØÎĵµ£º
ÔÎÄ£º¡¶Speeding up JavaScript: Working with the DOM¡·
×÷Õߣº KeeKim Heng, Google Web Developer
ÔÚÎÒÃÇ¿ª·¢»¥ÁªÍø¸»Ó¦Óã¨RIA£©Ê±£¬ÎÒÃǾ³£Ð´Ò»Ð©javascript½Å±¾À´Ð޸ĻòÕßÔö¼ÓÒ³ÃæÔªËØ£¬ÕâЩ¹¤×÷×îÖÕÊÇDOM——»òÕß˵Îĵµ¶ÔÏóÄ£ÐÍ——À´Íê³ÉµÄ£¬¶øÎÒÃǵÄʵÏÖ·½Ê½»áÓ°Ïìµ½Ó¦ÓõÄÏìÓ¦ËÙ¶È¡£
DO ......
ÀàµÄ¶¨ÒåÓÐ3ÖÖ»ù±¾·½·¨:
1¡¢´´½¨²¢ÄÜ·µ»ØÌض¨ÀàÐ͵ĶÔÏóµÄº¯Êý(¹¤³§º¯Êý)È磺
function wu()
{
var w=new object;
o.a=1;
return o;
}ÓÃÕâÖÖ·½Ê½´´½¨¶ÔÏó£ºvar u=wu();
2¡¢´´½¨¹¹Ô캯Êý£¬ÓÃnewʵÀý»¯ÀýÈ磺
function wu()
{this.a=1;}
ÓÃÕâÖÖ·½Ê½´´½¨¶ÔÏó: var u=new wu();
3¡¢ÔÐÍ·½Ê½,À ......
¶ÔÏóÊôÐÔ:
document.title //ÉèÖÃÎĵµ±êÌâµÈ¼ÛÓÚHTMLµÄ<title>±êÇ©
document.bgColor //ÉèÖÃÒ³Ãæ±³¾°É«
document.fgCol ......
1.document.write( " "); Êä³öÓï¾ä
2.JSÖеÄ×¢ÊÍΪ//
3.´«Í³µÄHTMLÎĵµË³ÐòÊÇ:document- >html- >(head,body)
4.Ò»¸öä¯ÀÀÆ÷´°¿ÚÖеÄDOM˳ÐòÊÇ:window- >(navigator,screen,history,location,document)
5.µÃµ½±íµ¥ÖÐÔªËØµÄÃû³ÆºÍÖµ:document.getElementById( "±íµ¥ÖÐÔªËØµÄID號 ").name(»òvalue)
6.Ò»¸ö ......
Ò»£¬½Å±¾³ÌÐòÓëjavascript
ǶÌ×ÔÚHTMLÖеÄÓïÑÔ³ÆÎª½Å±¾ÓïÑÔ£¬ä¯ÀÀÆ÷±ØÐë¾ßÓнű¾ÒýÇæ¶ÔǶÈëHTMLÖеĽű¾³ÌÐò½øÐнâÊÍ¡£
eg:
<HTML>
<script language="JavaScript">
//VBScript,Jscript,ECMAScript
<!--
alert(n ......