分類  >  Web前端 >

<一> web嫻忚鍣ㄤ腑鐨刯avascript

tags:    時間:2013-12-09 23:21:10
<1> web嫻忚鍣ㄤ腑鐨刯avascript
鍙傝€冭祫鏂欙細銆妀avascript鏉冨▉鎸囧崡銆嬪鎴風javascript閮ㄥ垎銆?

涓€銆亀eb嫻忚鍣ㄤ腑鐨刯avascript
鍦╳eb嫻忚鍣ㄤ綔涓轟笂涓嬫枃榪愯javascript鐨勮寖鍥村唴錛岄€氬父縐頒負瀹㈡埛絝痡avascript銆?

Window瀵硅薄鏄墍鏈夊鎴風Javascript鐗規€у拰API鐨勪富瑕佹帴鍏ョ偣錛屽畠琛ㄧずweb嫻忚鍣ㄧ殑涓€涓獥鍙f垨紿椾綋錛屽苟涓斿彲浠ョ敤鏍囪瘑絎︹€漺indow鈥濇潵寮曠敤瀹冿紝window瀹為檯涓婃槸涓€涓猈indow瀵硅薄寮曠敤鑷韓鐨勫睘鎬с€俉indow瀵硅薄瀹氫箟浜嗕竴浜涘睘鎬э紝姣斿鎸囦唬Loaction瀵硅薄鐨刲ocation灞炴€э紝Location瀵硅薄鎸囧畾褰撳墠鏄劇ず鍦ㄧ獥鍙d腑鐨剈rl錛屽苟鍏佽鑴氭湰寰€紿楀彛閲岃澆鍏ユ柊鐨剈rl錛屼細絝嬪嵆璺寵漿錛?
 // 璁劇疆location灞炴€э紝浠庤€岃煩杞埌鏂扮殑web欏甸潰 window.location = http://www.***.com


鍦ㄥ鎴風JavaScript涓紝window瀵硅薄涔熸槸鍏ㄥ矓瀵硅薄銆傝繖鎰忓懗鐫€Window瀵硅薄澶勪簬浣滅敤鍩熼摼鐨勯《閮紝瀹冪殑灞炴€у拰鏂規硶瀹為檯涓婃槸鍏ㄥ矓鍙橀噺鍜屽叏灞€鍑芥暟錛?strong>浣跨敤鍏ㄥ矓鍙橀噺鍜屽睘鎬т笉闇€瑕佹樉寮忕殑浣跨敤window鏉ュ紩鐢?/strong>銆備笂闈㈢殑渚嬪瓙涔熷彲浠ョ洿鎺ョ敤錛歭ocation = http://www.***.com

Window瀵硅薄鍏朵腑涓€涓噸瑕佺殑灞炴€ф槸document,瀹冨紩鐢―ocument瀵硅薄錛屽悗鑰呰〃紺烘樉寮忓湪紿楀彛錛坵indow瀵硅薄錛変腑鐨勬枃妗c€侱ocument瀵硅薄鏈変竴浜涢噸瑕佹柟娉曪紝姣斿getElementById()銆?
Window, Document, Element瀵硅薄涓婃湁寰堝閲嶈鐨勫睘鎬у拰鏂規硶錛屽悗闈細璇︾粏璁插埌銆?

1. Web鏂囨。錛坉ocument錛夐噷鐨刯avaScript
JavaScript紼嬪簭鍙互閫氳繃Document瀵硅薄鍜屽畠鍖呭惈鐨凟lement瀵硅薄閬嶅巻鍜岀鐞嗘枃妗e唴瀹廣€傚畠鍙互閫氳繃鎿嶇旱CSS鏍峰紡鍜岀被錛屼慨鏀規枃妗e唴瀹圭殑鍛堢幇錛涘苟涓斿彲浠ラ€氳繃娉ㄥ唽閫傚綋鐨勪簨浠跺鐞嗙▼搴忔潵瀹氫箟鏂囨。鍏冪礌鐨勮涓恆€傚唴瀹廣€佸憟鐜板拰琛屼負鐨勭粍鍚堬紝鍙仛鍔ㄦ€乭tml鎴朌HTML銆?

Web鏂囨。閲屽簲褰撳皯閲忎嬌鐢↗avaScript錛屽洜涓篔avascript鐪熸鐨勮鑹叉槸澧炲己鐢ㄦ埛鐨勬祻瑙堜綋楠岋紝浣誇俊鎮殑鑾峰彇鍜屼紶閫掓洿瀹規槗銆?

2. Web搴旂敤閲岀殑Javascript
鍦╳eb鏂囨。閲屼嬌鐢ㄧ殑JavaScript DHTML鐗規€у湪web搴旂敤涓兘浼氱敤鍒幫紝瀵逛簬web搴旂敤鏉ヨ錛岄櫎浜嗗唴瀹癸紝鍛堢幇鍜屾搷浣淎PI涔嬪錛岃繕渚濊禆浜哤EB嫻忚鍣ㄧ幆澧冩彁渚涚殑鏇村熀紜€鐨勬湇鍔°€?

瑕佺湡姝g悊瑙eb搴旂敤錛岃璁よ瘑鍒皐eb嫻忚鍣ㄦ笎娓愬彉鎴愪簡涓€涓畝鏄撶殑鎿嶄綔緋葷粺銆傝繖鏍峰氨鍙互鎶妛eb搴旂敤瀹氫箟涓虹敤Javascript璁塊棶鏇村嫻忚鍣ㄦ彁渚涚殑楂樼駭鏈嶅姟錛堝緗戠粶錛屽浘鍍忓拰鏁版嵁瀛樺偍錛夌殑web欏甸潰銆傞珮綰ф湇鍔¢噷鏈€鏈夊悕鐨勬槸XMLHttpRequest瀵硅薄錛屽彲浠ュHTTP璇鋒眰緙栫▼鏉ュ惎鐢ㄧ綉緇溿€俉eb搴旂敤浣跨敤榪欎釜鏈嶅姟浠庢湇鍔″櫒鑾峰彇鏂頒俊鎮紝鑰屼笉鐢ㄩ噸鏂拌澆鍏ラ〉闈€傜被浼艱繖鏍風殑web搴旂敤閫氬父鍙仛Ajax搴旂敤銆?

JavaScript鍦╳eb搴旂敤閲屼細姣斿湪web鏂囨。涓樉寰楁洿鍔犻噸瑕侊紝Javascript澧炲己浜唚eb鏂囨。錛屼絾鏄秹鍙婅壇濂界殑鏂囨。闇€瑕佸湪紱佺敤javascript鍚庤繕鑳界戶緇伐浣溿€俉eb搴旂敤鏈川涓婂氨鏄痡avascript紼嬪簭錛屽畠浣跨敤鐢眞eb嫻忚鍣ㄦ彁渚涚殑鎿嶄綔緋葷粺綾誨瀷鐨勬湇鍔★紝騫朵笖涓嶇敤鏈熸湜浠栦滑鍦ㄧ鐢ㄦ祻瑙堝櫒鑴氭湰鍚庤繕鑳芥甯稿伐浣溿€傚簲鐢ㄤ晶閲嶅拰鐢ㄦ埛鐨勪氦浜掑搷搴斻€?

浠庝笂闈袱鑺傚簲璇ユ竻妤歸eb欏甸潰鍜寃eb搴旂敤鐨勫尯鍒€?

3. 鍦╤tml閲屽祵鍏avascript
鍦╤tml閲屽祵鍏s鏈夊洓縐嶆柟娉曪細
1錛?鍐呰仈錛屾斁緗湪<script></script>鏍囩涔嬮棿銆?
2錛?鏀劇疆鍦?lt;script>鏍囩鐨剆rc灞炴€ф寚瀹氱殑澶栭儴鏂囦歡涓€?
3錛?鏀劇疆鍦╤tml浜嬩歡澶勭悊紼嬪簭涓紝璇ヤ簨浠跺鐞嗙▼搴忕敱onclick鎴杘nmouseover榪欐牱鐨刪tml灞炴€ф寚瀹氥€?
4錛?鏀懼湪涓€涓猽rl閲岋紝url浣跨敤鐗規畩鐨勨€漥avascript:url鈥濆崗璁€?

鏈€鍚庝竴縐嶆柟寮忕幇鍦ㄥ緢灝戜嬌鐢ㄤ簡錛屽唴鑱旇剼鏈嬌鐢ㄤ篃瓚婃潵瓚婂皯浜嗭紝鏈€濂界殑鏂瑰紡鏄斁鍦╯rc灞炴€ч噷錛堟湁涓紪紼嬪摬瀛﹀彨鈥渦nobtrusive JavaScript鈥濓紝涓誨紶鍐呭html鍜岃涓篬JavaScript浠g爜]搴斿綋灝介噺鍦板垎紱伙級銆?

3.1 <script>鍏冪礌
JavaScript浠g爜鍙互浠ュ唴鑱旂殑褰㈠紡鍑虹幇鍦℉TML鏂囦歡閲岀殑<script></script>鏍囩涔嬮棿錛?
<script>
// javascript浠g爜
</script>
鍦╔HTML涓紙XHTML姒傚康錛屼笌html鐨勫尯鍒鍙傝€冿細
http://baike.baidu.com/link?url=2R-H0wPp72NiX8DrpmEgT1CmhPR1yl6iS5Cdgd0CJZGZ4-iX0R95ma7oqSCsseD9錛夛紝<script>鏍囩涓殑鍐呭琚綋鍋氬叾浠栧唴瀹逛竴鏍峰寰呫€傚鏋淛avascript浠g爜鍖呭惈浜嗏€?lt;鈥濓紝 鈥?gt;鈥濇垨鈥?amp;鈥濆瓧絎︼紝閭d箞榪欎簺瀛楃灝變細琚В閲婃垚涓篨ML鏍囪錛屽洜姝わ紝濡傛灉浣跨敤XHTML,鏈€濂芥妸鎵€鏈夌殑javascript浠g爜鏀懼叆涓€涓狢DATA閮ㄥ垎錛?
<script>
<![CDATA[
// javascript浠g爜
]]>
</script>

Javascript鏄痺eb鐨勫師濮嬭剼鏈璦€錛?span style="color: red;">鍦ㄩ粯璁ゆ儏鍐典笅錛屽亣瀹?lt;script>鍏冪礌鍖呭惈鎴栧紩鐢╦avascript浠g爜銆傚鏋滀嬌鐢ㄩ潪javascript鑴氭湰錛屽垯瑕佷嬌鐢╰ype灞炴€ф寚瀹氳剼鏈殑MIME綾誨瀷錛?
<script type=鈥漷ext/vbscript鈥?gt;
// 榪欓噷鏄痸b浠g爜
</script>
Type灞炴€х殑榛樿鍊兼槸鈥漷ext/javascript鈥濄€?/strong>

鍙﹀錛?/strong>褰搘eb嫻忚鍣ㄩ亣鍒?lt;script>鍏冪礌錛屽苟涓旇繖涓厓緔犲寘鍚?span style="color: red;">涓?/span>琚祻瑙堝櫒璇嗗埆鐨則ype灞炴€ф椂錛屽畠浼氳В鏋愯繖涓厓緔犱絾涓嶄細灝濊瘯鎵ц鎴栨樉紺哄畠鐨勫唴瀹癸紝涔熶笉浼氫粠鎸囧畾鐨剈rl涓笅杞戒換浣曚笢瑗褲€傝繖鎰忓懗鐫€鍙互浣跨敤<script>鍏冪礌鏉ュ祵鍏ヤ換鎰忕殑鏂囨湰鏁版嵁鍒版枃妗i噷錛屽彧瑕佺敤type灞炴€ф寚瀹氫竴涓笉鍙墽琛岀殑綾誨瀷銆傝幏鍙栨暟鎹殑鏂規硶鏄敤琛ㄧず<script>鍏冪礌鐨凥TMLElement瀵硅薄鐨則ext灞炴€с€傛敞鎰忥紝榪欎簺鏁版嵁宓屽叆鎶€鏈?strong>鍙鍐呰仈鑴氭湰鐢熸晥銆?

3.2 澶栭儴鏂囦歡涓殑鑴氭湰
<script>鏍囩鏀寔src灞炴€э紝榪欎釜灞炴€ф寚瀹氬寘鍚獼avascript浠g爜鐨勬枃浠剁殑url錛岀敤娉曞涓嬶細
<script src=鈥?./../scripts/utils.js鈥?gt;</script>
JavaScript鏂囦歡鐨勬墿灞曞悕閫氬父鏄互.js緇撳熬鐨勶紝瀹冨寘鍚函綺圭殑javascript浠g爜錛屽叾涓棦娌℃湁<script>鏍囩錛屼篃娌℃湁鍏朵粬html鏍囩銆?




3.3 Html涓殑浜嬩歡澶勭悊紼嬪簭
褰撹剼鏈墍鍦ㄧ殑html鏂囦歡琚澆鍏ユ祻瑙堝櫒鏃訛紝榪欎釜鑴氭湰閲岀殑javascript浠g爜鍙細鎵ц涓€嬈°€備負浜嗗彲浜や簰錛屽繀欏誨畾涔変簨浠跺鐞嗙▼搴忥細web嫻忚鍣ㄥ厛娉ㄥ唽js鍑芥暟錛屽苟鍦ㄤ箣鍚庤皟鐢ㄥ畠浣滀負浜嬩歡鐨勫搷搴斻€傛敞鍐屼簨浠跺搷搴斿嚱鏁板彲浠ラ€氳繃緇檋tml鍏冪礌鐨勫睘鎬ц祴鍊礆紝姣斿onclick絳夊疄鐜般€?

3.4 url涓殑javascript
鍦╱rl鍚庨潰璺熶竴涓€漥avascript:鈥濆崗璁檺瀹氱鏄彟涓€縐嶅祵鍏avascript浠g爜鍒板鎴風鐨勬柟寮忋€傝繖縐嶇壒孌婄殑鍗忚綾誨瀷鎸囧畾url鍐呭涓轟換鎰忓瓧絎︿覆錛岃繖涓瓧絎︿覆鏄細琚玧avascript瑙i噴鍣ㄨ繍琛岀殑javascript浠g爜銆傝繖孌典唬鐮佷細琚綋鍋氬崟鐙殑涓€琛屽寰咃紝鎵€浠ヨ鍙ヤ箣闂村繀欏葷敤鍒嗗彿闅斿紑錛岃€屼笖娉ㄩ噴瑕佺敤/* */錛屼笉鑳界敤//錛宩avascript浠g爜鐨勮繑鍥炲€間綔涓簀avascript:url璇嗗埆鐨勮祫婧愶紝濡傛灉浠g爜榪斿洖undefined錛岄偅涔堣繖涓祫婧愭槸娌℃湁鍐呭鐨勩€傝繖縐嶇敤娉曞彲浠ヤ嬌鐢ㄥ湪浠諱綍浣跨敤url鐨勫湴鏂廣€傛瘮濡傦細
<a href=鈥漥avascript: new Date().toLocaleTimeString();鈥?gt; What time is it? </a>

閮ㄥ垎嫻忚鍣ㄤ細鎵цurl閲岀殑浠g爜騫朵嬌鐢ㄨ繑鍥炵殑瀛楃涓蹭綔涓哄緟鏄劇ず鏂版枃妗g殑鍐呭錛岄儴鍒嗘祻瑙堝櫒浼氭墽琛宩s浠g爜錛屼絾涓嶄細鍥炴樉榪斿洖鐨勫唴瀹癸紙榪欐椂鍙互閫氳繃浣跨敤alert寮瑰嚭鏄劇ず鐨勫瓧絎︿覆錛夈€?

鍓嶉潰鎻愬埌js榪斿洖undefined灝變笉浼氬洖鏄句換浣曞唴瀹癸紝榪樺彲浠?strong>閫氳繃void鎿嶄綔絎﹀己鍒?/strong>鍑芥暟璋冪敤鎴栫粰琛ㄨ揪寮忚祴浜坲ndefined鍊箋€傚錛?
<a href=鈥漥avascript:void window.open(鈥榓bout:blank鈥?;鈥?gt; 鎵撳紑涓€涓獥鍙? </a>


娉ㄦ剰錛歫avascript url鏄痺eb鏃╄搗鐨勯仐鐗╋紝閫氬父搴旇閬垮厤鍦ㄧ幇浠tml閲屼嬌鐢ㄣ€?

4. javascript紼嬪簭鐨勬墽琛?/strong>
瀹㈡埛絝痡avascript紼嬪簭娌℃湁涓ユ牸鐨勫畾涔夛紝鍙互璇磈avascript紼嬪簭鏃剁敱web欏甸潰涓墍鍖呭惈鐨?strong>鎵€鏈塲avascript浠g爜錛堜笂闈㈡彁鍒扮殑4涓祵鍏avascript鏂瑰紡錛?/strong>銆傛墍鏈夎繖浜涘崟鐙殑浠g爜鍏變韓鍚屼竴涓叏灞€Window瀵硅薄銆傝繖鎰忓懗鐫€浠栦滑閮藉彲浠ョ湅鍒扮浉鍚岀殑Document瀵硅薄錛屽彲浠ュ叡浜浉鍚岀殑鍏ㄥ矓鍑芥暟鍜屽彉閲忕殑闆嗗悎錛?span style="color: red;">濡傛灉涓€涓剼鏈畾涔変簡鏂扮殑鍏ㄥ矓鍙橀噺鎴栧嚱鏁幫紝閭d箞榪欎釜鍙橀噺鎴栧嚱鏁頒細鍦ㄨ剼鏈墽琛屼箣鍚庡浠繪剰javascript浠g爜鍙銆備笂闈㈣繖鍙ヨ瘽寰堥噸瑕併€?

濡傛灉web欏甸潰鍖呭惈涓€涓祵鍏ョ殑紿椾綋錛堥€氬父浣跨敤<iframe>鍏冪礌錛夛紝宓屽叆鏂囨。涓殑javascript浠g爜鍜岃宓屽叆鏂囨。閲岀殑javascript浠g爜浼氭湁涓嶅悓鐨勫叏灞€瀵硅薄錛屽畠鍙互褰撳仛涓€涓崟鐙殑javascript紼嬪簭銆傚鏋滃闈㈠拰閲岄潰鐨勬枃妗f潵鑷簬鍚屼竴涓湇鍔″櫒錛岄偅涓や釜鏂囨。涓殑浠g爜灝卞彲浠ヨ繘琛屼氦浜掋€?

Js紼嬪簭鐨勬墽琛屾湁涓や釜闃舵銆?/strong>絎竴闃舵錛岃澆鍏ユ枃妗e唴瀹癸紝騫舵墽琛?lt;script>鍏冪礌閲岀殑浠g爜錛堝寘鎷唴鑱斾唬鐮佸拰src鎸囧畾鐨勫閮ㄨ剼鏈級銆傝剼鏈€氬父鎸変粬浠湪鏂囨。閲岀殑鍑虹幇欏哄簭鎵ц錛屾墍鏈夎剼鏈殑js浠g爜閮芥槸浠庝笂寰€涓嬨€傛枃妗h澆鍏ュ畬鎴愶紝騫朵笖鎵€鏈夎剼鏈墽琛屽畬鍚庤繘鍏?span style="color: red;">絎簩闃舵銆傝繖涓樁孌墊槸寮傛鐨勶紝鐢變簨浠墮┍鍔ㄣ€備簨浠墮┍鍔ㄩ樁孌甸噷絎竴涓簨浠舵椂load浜嬩歡錛屾寚紺烘枃妗e凡緇忓畬鍏ㄨ澆鍏ワ紝騫跺彲浠ユ搷浣滐紙娉ㄦ剰js鐨刼nload涓巎query鐨剅eady鐨勫尯鍒級銆傞€氬父鍏朵粬鎵€鏈塲avascript浠g爜閮芥槸鍦╫nload浜嬩歡澶勭悊鏂規硶閲屽畾涔夈€?

娉ㄦ剰錛氭牳蹇僯avascript鍜屽鎴風javascript閮芥槸涓€涓?span style="color: red;">鍗曠嚎紼嬫墽琛屾ā鍨?/span>錛岃剼鏈拰浜嬩歡澶勭悊紼嬪簭鍦ㄥ悓涓€涓椂闂村彧鑳芥墽琛屼竴涓紝娌℃湁騫跺彂鎬с€?/strong>

1. 濡傛灉鎯寵紼嬪簭鍝嶅簲涓€涓簨浠訛紝鍐欎竴涓嚱鏁幫紝鍙仛鈥滀簨浠跺鐞嗙▼搴忊€濄€佲€滀簨浠剁洃鍚櫒鈥濇垨鈥滃洖璋冣€濓紝鐒跺悗娉ㄥ唽榪欎釜鍑芥暟錛岃繖鏍峰氨浼氬湪浜嬩歡鍙戠敓鏃惰皟鐢ㄥ畠錛屾敞鍐岀殑鏃跺€欏嚱鏁板苟娌℃湁琚皟鐢ㄣ€傛敞鍐屽彲浠ラ€氳繃鍑犵鏂瑰紡瀹炵幇錛?
錛?錛?strong>緇檋tml灞炴€ц祴鍊?/strong>銆傛寜鐓х害瀹氾紝浜嬩歡澶勭悊紼嬪簭鐨勫睘鎬х殑鍚嶅瓧鏄互鈥渙n鈥濆紑濮嬶紝鍚庨潰璺熺潃浜嬩歡鐨勫悕瀛椼€備簨浠跺鐞嗙▼搴忓彲浠ラ€氳繃html灞炴€ф潵瀹屾垚娉ㄥ唽錛屼絾涓嶉紦鍔卞皢js浠g爜鍜宧tml鍐呭娣鋒穯鍦ㄤ竴璧楓€傛渶綆€鍗曠殑鏂規硶鏄妸js鍑芥暟璧嬪€肩粰鐩爣瀵硅薄鐨勫睘鎬э紝綾諱技錛?
Window.onload = function(){};
Document.getElementById(鈥渂utton1鈥?.onclick = function(){};
Function handleResponse(){}
Request.onreadystatechange = handleResponse;
榪樺彲浠ラ€氳繃html鍏冪礌灞炴€ц祴鍊礆紝鍚庨潰璁插埌鑴氭湰鍖栨椂浼氳緇嗕粙緇嶃€?

錛?錛夊鏋滈渶瑕?strong>涓轟竴涓簨浠舵敞鍐屽涓鐞嗙▼搴?/strong>錛屽ぇ閮ㄥ垎鍙互鎴愪負浜嬩歡鐩爣鐨勫璞¢兘鏈変竴涓彨鍋歛ddEventListener()鐨勬柟娉曪紝鍏佽娉ㄥ唽澶氫釜鐩戝惉鍣ㄣ€傝繖涓柟娉曞悗闈細浠嬬粛銆?
瀵逛簬澶ч儴鍒嗘祻瑙堝櫒鐨勫ぇ閮ㄥ垎浜嬩歡鏉ヨ錛屼細鎶婁竴涓璞′紶閫掔粰浜嬩歡澶勭悊紼嬪簭浣滀負鍙傛暟錛岄偅涓璞$殑灞炴€ф彁渚涗簡浜嬩歡鐨勮緇嗕俊鎮紝姣斿鐐瑰嚮浜嬩歡鐨勫璞′細鏈変竴涓睘鎬ц鏄庨紶鏍囩殑鍝釜鎸夐挳琚崟鍑匯€?

瀹㈡埛絝痡avascript紼嬪簭榪樹嬌鐢ㄥ紓姝ラ€氱煡綾誨瀷錛岃繖浜涚被鍨嬪線寰€涓嶆槸浜嬩歡錛屾瘮濡俿etTimeout()鍜宻etInterval()閮芥槸window瀵硅薄鐨勬柟娉曪紝鏄叏灞€鏂規硶銆傚墠鑰呭彲浠ヨ緗湪鎸囧畾鐨勬縐掓暟涔嬪悗璋冪敤鏌愪釜鏂規硶錛屽悗鑰呮槸鍦ㄦ寚瀹氱殑姣鏁板悗閲嶅鎵ц鏌愪釜鏂規硶銆傚彲浠ョ敤閫掑綊鐨勬柟娉曡setTimeout杈懼埌setInterval鐨勬晥鏋溿€?

5. 瀹㈡埛絝痡avascript綰跨▼妯″瀷
Javascript璇█鏍稿績騫朵笉鍖呭惈浠諱綍綰跨▼鏈哄埗錛屽苟涓斿鎴風javascript浼犵粺涓婁篃娌℃湁瀹氫箟浠諱綍綰跨▼鏈哄埗銆傚崟綰跨▼鎰忓懗鐫€嫻忚鍣ㄥ繀欏誨湪鑴氭湰鍜屼簨浠跺鐞嗙▼搴忔墽琛岀殑鏃跺€欏仠姝㈠搷搴旂敤鎴瘋緭鍏ワ紝榪欐剰鍛崇潃javascript鑴氭湰鍜屼簨浠跺鐞嗙▼搴忎笉鑳借繍琛屽お闀挎椂闂淬€侶tml5瀹氫箟浜嗕竴縐嶅苟鍙戠殑鎺у埗鏂瑰紡錛屼綔涓哄悗鍙扮嚎紼嬬殑鈥渨ebworker鈥濄€俉eb worker鏄竴涓敤鏉ユ墽琛岃綆楀瘑闆嗕換鍔¤€屼笉鍐葷粨鐢ㄦ埛鐣岄潰鐨勫悗鍙扮嚎紼嬶紝浣嗘槸web worker綰跨▼閲岀殑浠g爜涓嶈兘璁塊棶鏂囨。鍐呭錛屼笉鑳藉拰涓葷嚎紼嬫垨鍏朵粬worker鍏變韓鐘舵€併€?

6. 瀹㈡埛絝痡avascript鏃墮棿綰?/strong>
鍓嶉潰綺楃暐鐨勬妸javascript鎵ц鍒嗕負涓や釜闃舵錛屼笅闈㈣緇嗙殑瑙i噴javascript紼嬪簭榪愯鐨勪簨浠剁嚎銆?





7. 鍏煎鎬у拰浜掔敤鎬?/strong>
Web嫻忚鍣ㄦ椂web搴旂敤鐨勬搷浣滅郴緇燂紝浣嗘槸web鏄竴涓瓨鍦ㄥ悇縐嶅樊寮傛€х殑鐜銆傚鐞嗕笉鍏煎闂鏈€綆€鍗曠殑鏂規硶鏄嬌鐢ㄧ被搴撱€?

8. 鍚屾簮絳栫暐
鍚屾簮絳栫暐鏄javascript浠g爜鑳藉鎿嶄綔鍝簺web鍐呭鐨勪竴鏉″畬鏁寸殑瀹夊叏闄愬埗銆傚綋web欏甸潰浣跨敤澶氫釜<iframe>鍏冪礌鎴栨墦寮€鍏朵粬嫻忚鍣ㄧ獥鍙g殑鏃跺€欙紝榪欎竴絳栫暐閫氬父浼氬彂鎸ヤ綔鐢ㄣ€傝繖縐嶆儏鍐典笅錛屽悓婧愮瓥鐣ヨ礋璐g鐞嗙獥鍙f垨紿椾綋涓殑javascript浠g爜浠ュ強鍜屽叾浠栫獥鍙f垨甯х殑浜や簰銆傚叿浣撴潵璇達紝鑴氭湰鍙兘璇誨彇鍜屾墍灞炴枃妗f潵婧愮浉鍚岀殑紿楀彛鍜屾枃妗g殑灞炴€?/span>銆?
鏂囨。鐨勬潵婧愬寘鍚崗璁€佷富鏈轟互鍙婅澆鍏ユ枃妗g殑url絝彛錛屼粠涓嶅悓web鏈嶅姟鍣ㄨ澆鍏ョ殑鏂囨。鍏鋒湁涓嶅悓鐨勬潵婧愶紱閫氳繃鍚屼竴涓繪満鐨勪笉鍚岀鍙h澆鍏ョ殑鏂囨。鍏鋒湁涓嶅悓鐨勬潵婧愶紱浣跨敤http鍗忚鍜宧ttps鍗忚杞藉叆鐨勬枃妗e叿鏈変笉鍚岀殑鏉ユ簮錛屽嵆浣誇粬浠潵鑷悓涓€涓湇鍔″櫒銆?

娉ㄦ剰錛氳剼鏈湰韜殑鏉ユ簮鍜屽悓婧愮瓥鐣ヤ笉鐩稿叧錛岀浉鍏崇殑鏄剼鏈墍宓屽叆鐨勬枃妗g殑鏉ユ簮銆?/strong>




鍙﹀錛氬湪鏌愪簺鎯呭喌涓嬪悓婧愮瓥鐣ユ樉寰楀お榪囦弗鏍間簡錛屾墍浠ュ紩鍏ヤ簡涓嶄弗鏍肩殑鍚屾簮絳栫暐錛屽彲浠ユ斁寮€涓€浜涜奼傦紝鍏蜂綋鍙互鏌ョ湅鍏跺畠鏂囨。銆?

9. 璺ㄧ珯鑴氭湰
璺ㄧ珯鑴氭湰錛圕ross-site scripting錛?鎴栬€呭彨鍋歑SS錛岃繖涓湳璇敤鏉ヨ〃紺轟竴綾誨畨鍏ㄩ棶棰橈紝涔熷氨鏄敾鍑昏€呭悜鐩爣web絝欑偣娉ㄥ叆html鏍囩鎴栬€呰剼鏈€?

10. 瀹㈡埛絝鏋?/strong>
涓€浜泈eb寮€鍙戣€呭彂鐜板熀浜庡鎴風妗嗘灦鎴栫被搴撴潵鍒涘緩浠栦滑鐨剋eb搴旂敤闈炲父渚挎嵎銆傜洰鍓嶅鎴風妗嗘灦寰堝錛屾瘮濡俲Query錛孌ojo, Prototype絳夈€備絾鏄悊瑙e簳灞俛pi浼氬府鍔╂垜浠垚涓烘洿浼樼鐨剋eb寮€鍙戣€呫€?

推薦閱讀文章

Bookmark the permalink ,來源:互聯網