这段代码能在火狐运行,不能在IE8上运行,求解。_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:33:29
原创
1413人浏览过

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>catalog</title><style type="text/css">  li{list-style:none;}a{color:black;text-decoration:none;}#catalog{      background-color:red;   padding-right:25px;   margin-right:20px;   float:left;}</style><script type="text/javascript">   var myboolean = new boolean(true);   function showtree(){      var tree = document.getelementbyid("tree");      var list = document.getelementbyid("list");      if(myboolean == true)      {           tree.value="-";           list.style="display:block;";           myboolean=false;        }       else      {           tree.value="+";           list.style="display:none;";           myboolean=true;       }   }</script></head><body><div id="catalog"><ul>  <li><input type="button" value="+" id="tree" onclick="showtree()" />帮助文档:</li>  <ul id="list" style="display:none;" >    <li><a href="http://www.baidu.com" target="content">办公室</a></li>  <li>绘图室</li>  </ul></ul></div><div id="content"><iframe name="content" width="1024" height="768" frameborder="0" ></iframe></div></body></html>
登录后复制

求高手看看,是不是兼容性问题,是的话如何修改下代码?跪谢。

一览运营宝
一览运营宝

一览“运营宝”是一款搭载AIGC的视频创作赋能及变现工具,由深耕视频行业18年的一览科技研发推出。

一览运营宝 41
查看详情 一览运营宝


回复讨论(解决方案)

 if(myBoolean == true)
      {
           tree.value="-";
            list.style.display="block";
           myBoolean=false; 
       }
       else
      {
           tree.value="+";
            list.style.display="none";
           myBoolean=true; 
      }
改成下面的就好了


IE8 IE 9  FF 都可以

写那么多,只要一句就可以实现了。。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>catalog</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script><style type="text/css">   li{list-style:none;}a{color:black;text-decoration:none;} #catalog{      background-color:red;   padding-right:25px;   margin-right:20px;   float:left;} </style> <script type="text/javascript">	$(function () {		$('#tree').bind('click', function () {			$('#list').toggle();		})	})</script></head><body><div id="catalog"><ul>  <li><input type="button" value="+" id="tree"/>帮助文档:</li>  <ul id="list" style="display:none;" >    <li><a href="http://www.baidu.com" target="content">办公室</a></li>  <li>绘图室</li>  </ul></ul></div><div id="content"><iframe name="content" width="1024" height="768" frameborder="0" ></iframe></div> </body></html>
登录后复制

另外,你的结构是有问题的。ul 里面写ul,那么第二个ul应该在li里面
你的不符合标准。


            

  •                         

                                          
    • ....

    •                         

           



下面改装:
<script type="text/javascript">	$(function () {		var ss = $('#catalog').find('li').not($('#catalog').find('li').eq(0));		ss.hide();		var x = 0;		$('#tree').click(function () {			if(x == 0) {				ss.show();				$('#tree').val('-');				x = 1;			} else {				ss.hide();				$('#tree').val('+');				x = 0;			}		})	})</script></head><body><div id="catalog"><ul>  <li><input type="button" value="+" id="tree"/>帮助文档:</li>  <li><a href="http://www.baidu.com" target="content">办公室</a></li>  <li>绘图室</li></ul></div>
登录后复制

另外,你的结构是有问题的。ul 里面写ul,那么第二个ul应该在li里面
你的不符合标准。


            

  •                         

                                          
    • ....

    •                         

           



下面改装:
<script type="text/javascript">	$(function () {		var ss = $('#catalog').find('li').not($('#catalog').find('li').eq(0));		ss.hide();		var x = 0;		$('#tree').click(function () {			if(x == 0) {				ss.show();				$('#tree').val('-');				x = 1;			} else {				ss.hide();				$('#tree').val('+');				x = 0;			}		})	})</script></head><body><div id="catalog"><ul>  <li><input type="button" value="+" id="tree"/>帮助文档:</li>  <li><a href="http://www.baidu.com" target="content">办公室</a></li>  <li>绘图室</li></ul></div>
登录后复制

多谢提醒,我会修正这个结构问题。
HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号