Javascript css菜单或脚本don';I don’我不在ie上工作
谢谢所有能帮助我的人 我在php上有一个css菜单,我在html上使用了以下脚本:Javascript css菜单或脚本don';I don’我不在ie上工作,javascript,internet-explorer,menu,Javascript,Internet Explorer,Menu,谢谢所有能帮助我的人 我在php上有一个css菜单,我在html上使用了以下脚本: <script type="text/javascript"> function showPic (whichpic) { if (document.getElementById) { document.getElementById('imgContenedor').src = whichpic.href; if (whichpic.title) { document.getEl
<script type="text/javascript">
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('imgContenedor').src = whichpic.href;
if (whichpic.title) {
document.getElementById('imgDescripcion').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
}
return false;
} else {
return true;
}
}
</script>
这里是错误
它在chrome上工作得很好,但在IE上没有,有什么想法吗???我真的不知道去哪里找 尝试使用
innerHTML
属性而不是nodeValue
:
function showPic (whichpic) {
if (document.getElementById) {
document.getElementById('imgContenedor').src = whichpic.href;
if (whichpic.title) {
document.getElementById('imgDescripcion').innerHTML = whichpic.innerHTML;
}
return false;
} else {
return true;
}
}
我刚刚读到有人抱怨每个人都推荐jQuery(或其他javascript框架),但这正是他们的用意。。。抽象出javascript实现中固有的差异 因此,无需进一步讨论,我将向您展示您的jQuery解决方案
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function showPic (whichpic) {
var wpic = jQuery(whichpic); // make our object jQuerified
jQuery('#imgContenedor').attr("src", wpic.attr("href"); // Set our image container
jQuery('#imgDescripcion').html(wpic.html()); // Set our image description
return false;
}
</script>
函数showPic(whichpic){
var wpic=jQuery(whichpic);//使对象jQuery化
jQuery('#imgContenedor').attr(“src”,wpic.attr(“href”);//设置图像容器
jQuery('#imgdescription').html(wpic.html());//设置图像描述
返回false;
}
您可以更进一步,删除内联onclick并执行
<script type="text/javascript">
jQuery("#celda_submenu li<a").click(showPic); // This will bind to all anchor (a) elements nested below an li inside an element with celda_submenu as the id.
</script>
jQuery(“#celda_子菜单li为什么ul元素定义了两次?
第一次是在桌子外面。
您的HTML似乎已损坏,这可能会导致浏览器之间的差异
<div id="subopciones" class="menudesp">
<table border="0" id="tabla_submenu" cellpadding="0" cellspacing="0">
<tr>
<td id='celda_submenu'><li><a href="" id='opcion_submenu' >Mobiliario Urbano</a>
<ul>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano01.jpg">  Circuito Espectacular Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano02.jpg">  Circuito Oppi Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano03.jpg">  Circuito Mupi Urbano Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano04.jpg">  Circuito Mupi Central Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano05.jpg">  Circuito Mupi Premium Barcelona</a></li>
</ul>
</li></td>
</tr>
</table>
IE有什么问题?我的意思是它根本不起作用,或者某个部分似乎失败了?ID为imgContenedor和IMGDescriptcion的html在哪里?你能在问题中也包括这一点吗?似乎有什么问题?什么不起作用?克莱德·洛博,我的意思是菜单不起作用(它没有显示菜单上的项目)我还删除了“点”"我上传了一张图片,你可以在左边的chrome上看到问题所在,在右边的ie上看到问题所在!谢谢!但是我做了你建议的更改;同样的结果!它在ie中不起作用!还有其他想法吗?嗯,迈克尔,谢谢你的帮助,但是我会尝试你说的,但是在ie上,它不起作用。你只是尝试了第一个吗只有t部分?你有什么错误吗?我可能打错了。是的,你有一个错误,a)是未命中的,但我及时看到了!;)但是当我使用你的代码而不是我的代码时,我得到了相同的结果,在chrome上好,在ie上坏!你正在使用什么版本的IE?还有,你能把包含imgContenedor和imgdescriptcion的HTML也包括进来吗?我在用IE 9,HTML的一部分,就是
我不知道可以是什么,我在和iMoses聊天,可能是css,我把它放在了我的原始帖子上!嗯,谢谢你对iMoses的帮助,但是我需要把那些ul-cos放进去,如果我不这样做的话,菜单会同时打开(在chrome和ie上),这是无效的HTML。告诉我你想实现什么,我们可能会找到一个解决方案,但你不能把一个表放在ul元素里面。这不会飞,会导致不同浏览器上的不同行为。嗨,iMoses,再次感谢!嗯,现在我想你是对的,也许问题出在css上,我要粘贴css重新编辑我的帖子,你能看一下吗?这将是一个很大的帮助!!!!那太好了!此外,您可以考虑在第一个LI(第一个UL的孩子)中移动表,或者在TD元素内移动第一个UL。这将保持相同的结构,同时使你的HTML再次有效。不,我不能这样做,因为我把它的代码不是所有的我有很多菜单更多!我只是把它的一部分。。。我现在要更新html的代码,包括所有的菜单,你会看到的(非常感谢!)
<script type="text/javascript">
jQuery("#celda_submenu li<a").click(showPic); // This will bind to all anchor (a) elements nested below an li inside an element with celda_submenu as the id.
</script>
<div id="subopciones" class="menudesp">
<table border="0" id="tabla_submenu" cellpadding="0" cellspacing="0">
<tr>
<td id='celda_submenu'><li><a href="" id='opcion_submenu' >Mobiliario Urbano</a>
<ul>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano01.jpg">  Circuito Espectacular Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano02.jpg">  Circuito Oppi Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano03.jpg">  Circuito Mupi Urbano Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano04.jpg">  Circuito Mupi Central Barcelona</a></li>
<li><a onclick="return showPic(this)" href="Imatges/productosnuevos/urbano05.jpg">  Circuito Mupi Premium Barcelona</a></li>
</ul>
</li></td>
</tr>
</table>