喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
 14  1/2  1  2  > 
     
标题: [问题] DOM兼容问题 高手来帮帮忙  
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
DOM兼容问题 高手来帮帮忙



<html>
<head>
  <title>JavaScript and the DOM</title>
  <script language="JavaScript">
   function test() {
    // These first two lines get the DOM tree for the current Web page,
    //   and then the <html> element for that DOM tree
    var myDocument = document;
    var htmlElement = myDocument.documentElement;

    // What's the name of the <html> element? "html"
    alert("The root element of the page is " + htmlElement.nodeName);

    // Look for the <head> element
    var headElement = htmlElement.getElementsByTagName("head")[0];
    if (headElement != null) {
      alert("We found the head element, named " + headElement.nodeName);
      // Print out the title of the page
      var titleElement = headElement.getElementsByTagName("title")[0];
      if (titleElement != null) {
        // The text will be the first child node of the <title> element
        var titleText = titleElement.firstChild;
        // We can get the text of the text node with nodeValue
        alert("The page title is '" + titleText.nodeValue + "'");
      }

      // After <head> is <body>
      var bodyElement = headElement.nextSibling;
      while (bodyElement.nodeName.toLowerCase() != "body") {
        bodyElement = bodyElement.nextSibling;
      }

      // We found the <body> element...

      // Remove all the top-level <img> elements in the body
      if (bodyElement.hasChildNodes()) {
        for (i=0; i<bodyElement.childNodes.length; i++) {
          var currentNode = bodyElement.childNodes[i];
          if (currentNode.nodeName.toLowerCase() == "img") {
            bodyElement.removeChild(currentNode);
          }
        }
      }
    }
  }
  </script>
</head>
<body>
  <p>JavaScript and DOM are a perfect match.
     You can read more in <i>Head Rush Ajax</i>.</p>
  <img src="http://www.headfirstlabs.com/Images/hraj_cover-150.jpg" />
  <input type="button" value="Test me!" onClick="test();" />
</body>
</html>
这段代码是正确的
但是第三个alert却在IE里无法正常显示运行
在firefox里就能够正常显示运行

请问高手如何才能让这段代码在任何浏览器上都能运行 解决一下兼容性的问题
2007-6-8 05:06 PM#1
查看资料  发短消息  QQ . .   顶部
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
[推荐阅读] 迎六一抚顺网通公司服务器机柜全面促销,最好的资源最的服务期待您的加入
哎呀 是真没人答么..........???
2007-6-11 11:04 AM#2
查看资料  发短消息  QQ . .   顶部
 
wzhu (wzhu)
版主
Rank: 7Rank: 7Rank: 7
C[A-Z]O


UID 68040
精华 0
积分 74247
帖子 1631
金钱 74180 喜悦币
威望 0
人脉 67
阅读权限 100
注册 2006-1-14
来自 湖北荆州>陕西西安>辽宁 ...
状态 离线
[推荐阅读] asp译成php的小问题
if (titleElement != null) {
        // The text will be the first child node of the <title> element
        var titleText = titleElement.text;
        // We can get the text of the text node with nodeValue
        alert("The page title is '" + titleText + "'");

试试

不敢担保




<?wzhu
wzhu.print("http://www.cncmm.com");
?>
2007-6-11 02:57 PM#3
查看资料  访问主页  Blog  发短消息  QQ . .   顶部
 
liuqh
中级会员
Rank: 3Rank: 3
中级会员


UID 30873
精华 0
积分 278
帖子 229
金钱 278 喜悦币
威望 0
人脉 0
阅读权限 30
注册 2004-9-1
来自 beijing php
状态 离线
[推荐阅读] 大家帮忙看看这个问题
建议直接研究JS框架,如:prototype、dojo等
2007-6-11 03:03 PM#4
查看资料  Blog  发短消息  QQ . .   顶部
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
[推荐阅读] 如何用PHP实现在某个时间点执行某些操作?
wzhu
你的方法我早就试过了 不过还是谢谢你
它返回的是空值
2007-6-12 08:13 AM#5
查看资料  发短消息  QQ . .   顶部
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
[推荐阅读] 上网很无聊
liuqh
也感谢你的回复,也谢谢你的建议
研究研究xslt也行,都能做出来
但是兼容的问题就是无法解决的么?
我是希望能得到一个解决兼容的问题
2007-6-12 08:15 AM#6
查看资料  发短消息  QQ . .   顶部
 
wzhu (wzhu)
版主
Rank: 7Rank: 7Rank: 7
C[A-Z]O


UID 68040
精华 0
积分 74247
帖子 1631
金钱 74180 喜悦币
威望 0
人脉 67
阅读权限 100
注册 2006-1-14
来自 湖北荆州>陕西西安>辽宁 ...
状态 离线
[推荐阅读] 超级难的js判断问题


QUOTE:
原帖由 dongyue91 于 2007-6-12 08:13 AM 发表
wzhu
你的方法我早就试过了 不过还是谢谢你
它返回的是空值
怪了,在我及其上就好的
你看看代码是否跟我说的一样

<html>
<head>
  <title>JavaScript and the DOM</title>
  <script language="JavaScript">
   function test() {
    // These first two lines get the DOM tree for the current Web page,
    //   and then the <html> element for that DOM tree
    var myDocument = document;
    var htmlElement = myDocument.documentElement;

    // What's the name of the <html> element? "html"
    alert("The root element of the page is " + htmlElement.nodeName);

    // Look for the <head> element
    var headElement = htmlElement.getElementsByTagName("head")[0];
    if (headElement != null) {
      alert("We found the head element, named " + headElement.nodeName);
      // Print out the title of the page
      var titleElement = headElement.getElementsByTagName("title")[0];
      if (titleElement != null) {
        // The text will be the first child node of the <title> element
        var titleText = titleElement.text;
        // We can get the text of the text node with nodeValue
        alert("The page title is '" + titleText + "'");
      }

      // After <head> is <body>
      var bodyElement = headElement.nextSibling;
      while (bodyElement.nodeName.toLowerCase() != "body") {
        bodyElement = bodyElement.nextSibling;
      }

      // We found the <body> element...

      // Remove all the top-level <img> elements in the body
      if (bodyElement.hasChildNodes()) {
        for (i=0; i<bodyElement.childNodes.length; i++) {
          var currentNode = bodyElement.childNodes;
          if (currentNode.nodeName.toLowerCase() == "img") {
            bodyElement.removeChild(currentNode);
          }
        }
      }
    }
  }
  </script>
</head>
<body>
  <p>JavaScript and DOM are a perfect match.
     You can read more in <i>Head Rush Ajax</i>.</p>
  <img src="http://www.headfirstlabs.com/Images/hraj_cover-150.jpg" />
  <input type="button" value="Test me!" onClick="test();" />
</body>
</html>


 附件: 您所在的用户组无法下载或查看附件



<?wzhu
wzhu.print("http://www.cncmm.com");
?>
2007-6-12 08:37 AM#7
查看资料  访问主页  Blog  发短消息  QQ . .   顶部
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
[推荐阅读] 卖两本书
var titleText = titleElement.text;
        alert("The page title is '" + titleText + "'");

是我大意了,奇怪你的这个怎么就好使呢

    var titleText = titleElement.titleElement.firstChild;
        alert("The page title is '" + titleText.nodeValue + "'");

这个怎么就不灵呢,这个在firefox下就好使的啊.
2007-6-12 09:00 AM#8
查看资料  发短消息  QQ . .   顶部
 
wzhu (wzhu)
版主
Rank: 7Rank: 7Rank: 7
C[A-Z]O


UID 68040
精华 0
积分 74247
帖子 1631
金钱 74180 喜悦币
威望 0
人脉 67
阅读权限 100
注册 2006-1-14
来自 湖北荆州>陕西西安>辽宁 ...
状态 离线
[推荐阅读] 北京招聘php程序员
主要是IE和FF对DOM节点理解的不同而已,你最好看看FF和IE是如何理解DOM节点结构的。



<?wzhu
wzhu.print("http://www.cncmm.com");
?>
2007-6-12 09:26 AM#9
查看资料  访问主页  Blog  发短消息  QQ . .   顶部
 
dongyue91
新手上路
Rank: 1



UID 86040
精华 0
积分 14
帖子 16
金钱 14 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-1-11
来自 辽宁省盘锦市
状态 离线
[推荐阅读] php Ubb类
哦,谢谢,我百度搜搜看吧,我没有你说的那方面资料
2007-6-12 09:59 AM#10
查看资料  发短消息  QQ . .   顶部
 14  1/2  1  2  > 
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.026667 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP