Re: 答复: 由webcomponents中引用外部JS的问题联想到的一个建议

鏄殑

鍙戣嚜鎴戠殑 iPad

> 鍦 2015骞3鏈11鏃ワ紝15:15锛孒awkeyes Wind <hawkeyes0@hotmail.com> 鍐欓亾锛
> 
> 涔熷氨鏄锛屾牴鎹畇rc璁$畻鍚庣殑uri璺緞鏉ュ垽鏂紵
>  
>  
> Hawkeyes Wind
>  
> <image001.png>
>  
> 鍙戜欢浜: 閿︽睙 璧 [mailto:zhaojinjiang@me.com] 
> 鍙戦佹椂闂: 2015骞3鏈11鏃 13:59
> 鏀朵欢浜: HawkeyesAngel
> 鎶勯: 'W3C HTML5 涓枃鑸堣叮灏忕祫'
> 涓婚: Re: 鐢眞ebcomponents涓紩鐢ㄥ閮↗S鐨勯棶棰樿仈鎯冲埌鐨勪竴涓缓璁
>  
> 鎴戣鎯崇殑鍒ゆ柇鏂瑰紡鍜孒TML Imports涓殑鍘婚噸鏂瑰紡绫讳技锛屽嵆濡傛灉鍏堝悗澶氭寮曞叆浜嗗悓涓涓剼鏈枃浠讹紝鍒欒繖涓枃浠朵腑鐨勮剼鏈彧鍦ㄧ涓娆″嚭鐜扮殑鍦版柟鎵ц
>  
> 璧甸敠姹
> 
> 2015骞3鏈11鏃 涓婂崍01:59锛孒awkeyesAngel <hawkeyes0@hotmail.com> 鍐欓亾锛
> 
> hi 閿︽睙锛
>     浣犺鎯崇殑once灞炴у垽鏂剼鏈槸鍚﹀凡鍔犺浇鐨勬爣鍑嗘槸浠涔堬紵
>  
> 鍙戣嚜 Windows 閭欢
>  
> 鍙戜欢浜: 璧甸敠姹
> 鍙戦佹椂闂: 鈥2015鈥庡勾鈥3鈥庢湀鈥10鈥庢棩, 鈥庢槦鏈熶簩 鈥22鈥:鈥29
> 鏀朵欢浜: 'W3C HTML5 涓枃鑸堣叮灏忕祫'
>  
> 澶у濂斤紝
>  
> 濡傞锛岃儗鏅槸杩欐牱鐨勶細
>  
> # 鑳屾櫙
>  
> 鍦╳ebcomponents[1]涓紝鎴戜滑鍙互閫氳繃HTML Imports鐨勬柟寮忔妸浠g爜鍒嗘垚澶氫釜鏂囦欢鍔犺浇锛屾瘡涓枃浠堕噷瀹氫箟涓涓垨澶氫釜缁勪欢銆
> 涓嶅悓鐨勭粍浠跺彲浠ヤ緷璧栫浉鍚岀殑澶栭儴JS搴擄紝姣斿缁勪欢A鍜岀粍浠禕閮戒緷璧杍Query銆
>  
> 杩欎釜鏃跺欙紝鎴戣兘鎯冲埌鐨勬瘮杈冨畬澶囩殑鍐欐硶鍙兘鏄細
> 1. 鍐欎竴涓嫭绔嬬殑缁勪欢jquery.html锛
>  
> ```html
> <script src="jquery.js"></script>
> ```
>  
> 2. 缁勪欢A鍜岀粍浠禕閮界敤HTML Imports鐨勬柟寮忓紩鍏query.html锛
>  
> a.html锛
> ```
> <link rel="import" href="jquery.html">
> <script src="jquery.ui.js"></script>
> (缁勪欢A鐨勪唬鐮)
> ```
>  
> b.html锛
> ```
> <link rel="import" href="jquery.html">
> (缁勪欢B鐨勪唬鐮)
> ```
>  
> 濡傛灉鑰冭檻鍒板皢鏉ョ殑鍙墿灞曟э紝jquery.ui.js鏈濂戒篃鍐欐垚涓涓猨query.ui.html鐨凥TML Imports銆
> 浣嗘槸杩欑鍐欐硶寰堥夯鐑︼紝灏ゅ叾瀵逛簬绗笁鏂圭殑JS搴撴潵璇达紝娌℃湁鐜版垚鐨凥TML Imports渚涗綘寮曠敤锛岄兘寰楄嚜宸卞啓锛屾瘡娆″鐢ㄥ埌涓涓閮↗S锛屼綘鍙兘灏卞緱鑷繁澶氬啓涓涓狧TML Imports鏂囦欢
>  
> # 寤鸿
>  
> 缁<script>鏍囩鍔犲叆涓涓猳nce鐨刟ttribute锛屽鏋滄湁once杩欎釜attribute锛屽垯鐩稿悓鐨凧S鐜涓嬶紝鐩稿悓src鐨<script>鍙姞杞藉苟鎵ц涓娆★紝鍜<import rel="import">鏄竴鏍风殑浼氣滃幓閲嶁
>  
> 杩欐牱鐨勮瘽涔嬪墠鐨勪唬鐮佸彲浠ユ敼鍐欐垚杩欐牱锛
>  
> jquery.html 涓嶅啀闇瑕佷簡
>  
> a.html锛(寤鸿鎵鏈夌殑js渚濊禆閮藉姞once)
> ```
> <script src="jquery.js" once></script>
> <script src="jquery.ui.js" once></script>
> (缁勪欢A鐨勪唬鐮)
> ```
>  
> b.html锛
> ```
> <script src="jquery.js" once></script>
> (缁勪欢B鐨勪唬鐮)
> ```
>  
> # 鎬荤粨
>  
> 鎬荤粨涓涓嬪氨鏄缓璁粰<script>鏍囩鍔犲叆once鐨刟ttribute锛岃В鍐冲涓獁ebcomponents涓閮↗S渚濊禆绠$悊 (鍚屾椂缁濆ぇ澶氭暟宸叉湁鐨勫閮↗S娌℃湁鑷繁鐨凥TML Imports) 鐨勯棶棰
>  
> [1] http://w3c-html-ig-zh.github.io/webcomponents/

>  
> 浠ヤ笂
> 璋㈣阿
>  
> 璧甸敠姹

Received on Wednesday, 11 March 2015 09:35:19 UTC