ûÓа´±ðÈ˵ÄÍÆ¼ö£¬Ñ§Ê²Ã´Ê¥¾ÀàµÄjsÊ飬¶øÊÇËæ±ãÌôÁ˱¾¡¶JavaScript in 10 Steps or Less¡·¡£
»¨ÁË3¸öСʱ£¬¿´ÁË30¸ötask¡£
½²µÄ·Ç³£Ç³ÏÔÏêϸ¡£ËäÈ»ÊÇEÎÄ£¬µ«ºÜdzÏÔÒ×¶®¡£
task31:
Calling Functions from Tags
One of the benefits of JavaScript is to be able to tie interactivity to elements of the HTML page. One way you can do this is to set up links in HTML that actually trigger calls to JavaScript functions when the link is clicked.
There are two ways to do this:
1. Use the onClick attribute of the a tag to call the function:
<a href=”#” onClick=”functionName()”>Link text</a>
2. Use a javascript: URL in the href attribute of the a tag to call
the function:
<a href=”javascript:functionName()”>Link text</a>
The following task illustrates these two methods of calling a function from a link by creating a function that displays an alert dialog box to the user and then providing two separate links for the user to use to call the fun ......
1. SproutCore
SproutCore Æ»¹û¶ÔSproutCoreµÄ½âÊÍΪ“¿ªÔ´£¬Æ½Ì¨Î޹أ¬ÀàCocoaµÄJavaScript¿ò¼Ü£¬ÓÃÓÚ´´½¨¾ßÓÐ×ÀÃæÓ¦ÓóÌÐòÍâ¹ÛºÍ²Ù×÷¸ÐµÄWebÓ¦ÓóÌÐò¡£”
SproutCore demonstrations: Photos, Sample Controls
2. Spry
Spry ÊÇAdobe µÄ Ajax framework. SpryµÄÄ¿µÄÊdzÉΪʵÏÖAjaxµÄÒ»ÖÖ¼òµ¥·½Ê½£¬¶ÔHTML¡¢CSSºÍJavaScriptÌåÑé¾ÝÓÐÈëÃż¶Ë®Æ½µÄÉè¼ÆÈËÔ±Ó¦¸ÃÄܹ»·¢ÏÖSpryÊÇÒ»ÖÖÕûºÏÄÚÈݵļòµ¥·½·¨¡£
Spry demonstrations: Photo Gallery, RSS Reader, Form Validation Widgets
3. JavaScriptMVC
JavaScriptMVC ÊÇÒ»¸ö¹¦ÄÜÇ¿´óµÄ JavaScript framework. Ò²ÊÇÒ»¸öºÜ°ôµÄJavaScript²âÊÔ¿ò¼Ü£¬ËüͬÑùÄÜÌá¸ß¿ª·¢µÄËÙ¶È¡£JavaScriptMVCÓ¦ÓÃÁËÄ£ÐÍ-ÊÓͼ-¿ØÖÆÆ÷¼Ü¹¹Ä£Ê½£¬°ÑÒµÎñÂß¼ºÍ±íʾ·ÖÀ룬ʹµÃ´úÂë¸ü¼ÓÄ£¿é»¯¡£
JavaScriptMVC demonstrations: Error Demo, History Demo, Todo Demo
4. qooxdoo
qooxdoo ÊÇÒ»¸ö Ajax Ó¦Óÿò¼ÜʹÓûùÓÚÃæÏò¶ÔÏó JavaScript. qooxdooÊÇÒ»¸ö¹¦ÄÜÇ¿´ó»ùÓÚJavaScript GUI¹¤°ü£¬ËüÈÃÄã¿ÉÒÔÓÃJavaScriptÀ´¿ª·¢ÀàËÆÓÚVB/Delphi·ç¸ñµÄ¾ßÓÐAjax¹¦ÄܵÄweb2.0Ó¦ÓóÌÐò¡£qooxdoo¾ßÓпͻ§¶Ëä¯ÀÀÆ÷¼ì²â¹¦ÄÜ£¬¾ßÓÐä¯ÀÀÆ÷³éÏó²ã£¬¿ÉÒÔÎÞ²î±ðµÄ ......
javascriptÖеÄÃæÏñ¶ÔÏñ¡£
Çë¿´´úÂ룬ÏÂÃæµ¯³öÒ»¸ö¶Ô»°¿ð¡£
<script type="text/javascript">
function win(w, h,,url)
{
this.width = 100;
this.height = 300;
this.time = 10;
this.url = url;
this.openWin = function()
{
var iTop = (window.screen.availHeight) / 2;
&nb ......
ÃèÊö
event´ú±íʼþµÄ״̬£¬ÀýÈç´¥·¢event¶ÔÏóµÄÔªËØ¡¢Êó±êµÄλÖü°×´Ì¬¡¢°´ÏµļüµÈµÈ¡£
event¶ÔÏóÖ»ÔÚʼþ·¢ÉúµÄ¹ý³ÌÖвÅÓÐЧ¡£
eventµÄijЩÊôÐÔÖ»¶ÔÌØ¶¨µÄʼþÓÐÒâÒå¡£±ÈÈ磬fromElement ºÍ toElement ÊôÐÔÖ»¶Ô onmouseover ºÍ onmouseout ʼþÓÐÒâÒå¡£
Àý×Ó
ÏÂÃæµÄÀý×Ó¼ì²éÊó±êÊÇ·ñÔÚÁ´½ÓÉϵ¥»÷£¬²¢ÇÒ£¬Èç¹ûshift¼ü±»°´Ï£¬¾ÍÈ¡ÏûÁ´½ÓµÄÌø×ª¡£
<HTML>
<HEAD><TITLE>Cancels Links</TITLE>
<SCRIPT LANGUAGE="JScript">
function cancelLink() {
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false;
}
</SCRIPT>
<BODY onclick="cancelLink()">
ÏÂÃæµÄÀý×ÓÔÚ״̬À¸ÉÏÏÔʾÊó±êµÄµ±Ç°Î»Öá£
<BODY onmousemove="window.status = 'X=' + window.event.x + ' Y=' + window.event.y">
ÊôÐÔ£º
altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y
1.altKey
ÃèÊö£º
¼ì²éalt¼üµÄ× ......
Êý×éÊôÓÚJavaScriptÖеĸ´ºÏÊý¾ÝÀàÐÍ¡£
JavaScriptÖÐÒ»¸öÊý×é¿ÉÒÔ´æ´¢JavaScriptÖ§³ÖµÄÈκÎÊý¾ÝÀàÐÍ£¬±ÈÈç¿ÉÒÔÓÃÒ»¸öÊý×éÀ´´¦ÀíÓû§´ÓÖÐÑ¡ÔñµÄÏîÄ¿ÁÐ±í£¬»òÕßÒ»×éͼÏñ×ø±ê£¬»òÕßÒ»×éͼƬµÄÒýÓá£
´´½¨Array¶ÔÏó²¢³õʼ»¯
1 var preInitArray = new Array(“First item”,”Second item”,”Third item”);
2 var preDeterminedSizeArray = new Array(3);
3 var anArray = new Array();
anArray[0] = “anItem”;
anArray[1] = “anotherItem”;
4 var myArray = [1,2,3];
5 var yourArray = [“red”,”green”,”blue”];
Êý×éÖеÄϱê
1 ʹÓÃË÷ÒýÊý´æ´¢Êý¾ÝÏî·½±ãÑ»·Õû¸öÊý×é
2 Ò²¿ÉÒÔʹÓùؼü×ÖÀ´·ÃÎÊÊý¾ÝÔªËØ£¬ÔÚÈçÏÂÇé¿öÏ·dz£ÓÐЧ£¬Èç¿ÉÒÔ¸øÊý¾Ý·ÖÅäÓÐÓõıêÇ©£¬»òÕߴ洢һЩֻÓÃÔÚÉÏÏÂÎÄÖвÅÓÐЧµÄʵÌåµÄµØ·½£¬ÈçÒ»¸öͼÏñ×ø±êÁбí
¿ÉÊÇ£¬Èç¹ûËüÃÇÒѾʹÓùؼü×Ö±»ÉèÖÃÁË£¬ÄÇô²»ÄÜʹÓÃË÷ÒýÊýÀ´·ÃÎÊʵÌ壨ÔÚÆäËûÓïÑÔÈçPHP ......
/********************************************************************************/
//javascriptÔÚÁ½¸ö¸¡µãÊýÔËËãµÄʱºò»áÓбȽÏÃ÷ÏÔµÄÎó²î¡£Ôö¼ÓÏÂÁз½·¨½â¾ö¡£
//2009-07-18 Skyeah
//³ý·¨º¯Êý£¬ÓÃÀ´µÃµ½¾«È·µÄ³ý·¨½á¹û
//˵Ã÷£ºjavascriptµÄ³ý·¨½á¹û»áÓÐÎó²î£¬ÔÚÁ½¸ö¸¡µãÊýÏà³ýµÄʱºò»á±È½ÏÃ÷ÏÔ¡£Õâ¸öº¯Êý·µ»Ø½ÏΪ¾«È·µÄ³ý·¨½á¹û¡£
//µ÷ÓãºaccDiv(arg1,arg2)
//·µ»ØÖµ£ºarg1³ýÒÔarg2µÄ¾«È·½á¹û
function accDiv(arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
......