简体   繁体   English

ie和firefox中列表选择的不同行为?

[英]Different behavior of list selection in ie and firefox?


<ul id='reorderps'>
<li><span><a href=''>+</a>Item 1</span></li>
 <ul>
   <li><span><a href=''>+</a>Sub Item 1</span></li>
   </ul>
 </ul>

I have a unordered list like this with level 1 and level 2 items when i am trying to do a 当我尝试执行以下操作时,我有一个像这样的无序列表,其中包含第1级和第2级项目

jQuery('a').parent().parent().html(); it is behaving differently in ie. 即在行为上有所不同。 In IE it is taking ul below it as its child but in mozilla it isnt. 在IE中,它以ul以下为子级,但在mozilla中则不是。 What can be the cause and solution to it. 可能是什么原因和解决方案。

I've tested in IE & Firefox, and in both it take same` +Item 1 我已经在IE和Firefox中进行了测试,两者都使用相同的+项目1

Also you have missed brackets with first parent,I've tested like this for example 您也错过了与第一亲的括号,例如,我已经测试过了

$("#reorderps").append(jQuery('a').parent().parent().html());

And in result I have this in both browsers 结果我在两个浏览器中都有这个

+Item 1
+Sub Item 1
+Item 1

Here is jsfiddle http://jsfiddle.net/sUxyt/1/ 这是jsfiddle http://jsfiddle.net/sUxyt/1/

Why Item 1?Because jQuery('a') returns array to you, and jQuery('a') means jQuery('a').eq(0) 为什么选择第1条?因为jQuery('a')返回数组给你,而jQuery('a')意味着jQuery('a').eq(0)

If you want to take next line you must write something kind of this 如果您想采用下一行,则必须写一些这样的内容

$("#reorderps").append(jQuery('a').eq(1).parent().parent().html());

In this situation you must get this in example of my jsfiddle 在这种情况下,您必须以我的jsfiddle示例为例

+Item 1
+Sub Item 1
+Sub Item 1

EDIT: 编辑:

I change Javascript part as you want,like this 我可以根据需要更改Javascript部分

jQuery('ul#reorderps a').click(function(e){ alert(jQuery(this).parent().parent().html()); e.preventDefault(); });

And yeah, there is a difference in IE 7 & other browsers. 是的,IE 7和其他浏览器有所不同。 All is need to change your html from this 所有需要从这里更改您的html

<ul id='reorderps'>
<li><span><a href=''>+</a>Item 1</span></li>
 <ul>
   <li><span><a href=''>+</a>Sub Item 1</span></li>
   </ul>
 </ul>

to

<ul id='reorderps'>
<li><span><a href=''>+</a>Item 1</span></li>
    <li>
 <ul>
   <li><span><a href=''>+</a>Sub Item 1</span></li>
   </ul>
    </li>
 </ul>

The reason of that behavior is that IE 7 doesn't recognize the end tag of your li, and take the innerHTML of your li little bit larger. 该行为的原因是IE 7无法识别li的结束标记,而将li的innerHTML增大了一点。 Adding li to second part solve the problem:) 在第二部分添加li可解决问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM