`
Duno
  • 浏览: 32989 次
  • 来自: ...
社区版块
存档分类
最新评论

What's wrong with this and the difference?

    博客分类:
  • js
阅读更多
目的:动态加载javascript
两种方式:
1.
function include(src) {
	HTMLCode = '<script language="javascript" src="' + src + '"></script>';
	var tags = document.getElementsByTagName("head");
	var html = tags[0].innerHTML;
        tags[0].innerHTML = HTMLCode + html;
}



2.
function include(src) {
	var s = document.createElement('script');
	s.src = src;
	var tags = document.getElementsByTagName("head");
	tags[0].appendChild(s);
}


假设动态加载的src中含有全局变量 var all=123;
测试的时候第一种方式是拿不到这个全局变量的,而第二种是可以的,但两种方式下inspect可以看到文档中均已经加载src,想请教缘由?

分享到:
评论
3 楼 Duno 2008-02-22  
记录下:http://hi.baidu.com/jia818915/blog/item/75c2c61f4c50c161f624e485.html
2 楼 黎明破晓前 2008-02-22  
innerHTML对于head标签来说是只读的
我这里你的第一种根本插入不了script,你的可以?
1 楼 boin 2008-02-22  
“对于IE,首先 script 标签必须带 defer 属性,其次在插入时刻,innerHTML 的所属节点必须在 DOM 树中;对于 Firefox 和 Opera,在插入时刻,innerHTML 的所属节点不可以在 DOM 树中。”

innerHTML 不是标准属性,各个浏览器实现都有差异。

相关推荐

    Yunus, Muhammad - Creating A World Without Poverty; Social Business and the Future of Capitalism

    Infused with entrepreneurial spirit and the excitement of a worthy challenge, this book is the opposite of pessimistic recitals of intractable poverty's horrors. -----------------------------------...

    HANA FAQ (frequently asked question)

    37. What is the difference between the SAP HANA enterprise edition and the SAP HANA platform edition? 38. Are there any special SAP HANA options that can be purchased on top of the standard SAP HANA ...

    计算机网络第六版答案

    This document contains the solutions to review questions and problems for the 5th edition of Computer Networking: A Top-Down Approach by Jim Kurose and Keith Ross. These solutions are being made ...

    Manage Software Testing

    • Investment analysts who want to know what might go wrong with their investments, why, and how to stop it. • Project office staff who want to know how to integrate the information they get from the...

    Clean Code

    And you will be challenged to think about what’s right about that code, and what’s wrong with it. More importantly, you will be challenged to reassess your professional values and your commitment ...

    BobBuilder_app

    I have chosen the 10000 number as a good case in both read and writes, you are welcome to tinker with this on your own systems and see what works better for you. Performance Tests v2.3 In v2.3 a ...

    cisco_ios_access_lists.pdf

    A brief note about what I cover: the access lists in this book deal only with the Internet Protocol (IP), though you could probably use many of the same techniques with other network protocols as ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    As every C++ programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain....

    德伯家的苔丝英语原文下载

    The more austere of these maintain a conscientious difference of opinion concerning, among other things, subjects fit for art, and reveal an inability to associate the idea of the sub-title adjective ...

    C# Game Programming Cookbook for Unity 3D - 2014

    1. Making Games the Modular Way 1 1.1 Important Programming Concepts.....................................2 1.1.1 Manager and Controller Scripts...............................2 1.1.2 Script ...

    VB编程资源大全(英文源码 其它)

    6 , chunks.zip This will open a file and read it in "Chunks" of a selected file.&lt;END&gt;&lt;br&gt;7 , logging.zip This is a bas that will log installation procedures so the file can be removed later....

    Build Report Tool 3.0.19.rar

    3. Size Stats: Shows the build's file size, and a table breaking down of which assets are taking up what percentage of space on the build. 4. Used Assets: Shows a list of *all* assets that were ...

    2018年秋季湖北省重点高中联考协作体期中考试高一英语答案.docx.docx

    Is there any difference between the books? - W: There are pictures in the expensive one. - **知识点:** - **词汇:**expensive(昂贵的)、cheaper(更便宜的)、picture(图片) - **语法:**使用比较级...

    一个win32下的ARM开源编译器

    3) SRS with writeback must have a separating space after the mode number and before "!" (eg. "SRSDB 16 !" instead of "SRSDB 16!") 4) macro, rept, irp, format, if, virtual etc. are all significant ...

    英语表达法.pdf

    6. “What's the weather like today?” 是询问天气状况的常用句式。 7. “Where are you headed?” 用于询问对方的目的地或计划去的方向。 8. “I wasn't born yesterday.” 表示自己并不天真,对某些事情有所...

    想学口语就看必备的东西

    5. **What's the weather like today?**(今天天气怎么样?):了解当天天气状况的基本句型。 6. **Where are you headed?**(你要去哪儿?):询问目的地或下一步计划时使用。 7. **I wasn't born yesterday.**(我...

    大学生应该脱口而出的100个精典英文句子

    - **例句**: "This place isn’t perfect but it’s good enough." "Don’t be so fussy!" #### 16. Don’t count on me! 别指望我! - **应用场景**: 表示不愿意或不能参与某事。 - **例句**: "We’re going to ...

    英语228句口语要素

    5. **What's the weather like today?**(今天天气怎么样?):询问天气状况,常用于寒暄。 6. **Where are you headed?**(你要去哪里?):询问对方的目的地或计划。 7. **I wasn't born yesterday.**(我不是...

Global site tag (gtag.js) - Google Analytics