Unable to get a jQuery script work in Firefox

Unable to get a jQuery script work in Firefox

葬花如无物 发布于 2021-11-24 字数 3271 浏览 615 回复 4 原文

I have the following script in my homepage

$(function () { // same as $(document).ready(function () { })
  // assuming we have the open class set on the H2 when the HTML is delivered
  $('li.drawer h2:not(.open)').next().hide();

  $('h2.drawer-handle').click(function () {
    // find the open drawer, remove the class, move to the UL following it and hide it
    $('h2.open').removeClass('open').next().hide();

    // add the open class to this H2, move to the next element (the UL) and show it
    $(this).addClass('open').next().show();
  });
});

It works in Safari, but not in Firefox 3.08/3.1 beta3.

How can you get the above jQuery script work in Firefox?

[edit]

First lines of my index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
<link href="template.css" type="text/css" rel="stylesheet"/>
<title>Abc</title>

<script type="text/javascript" src="jquery.js" />  

<script type="text/javascript"> 

! - - - - Above Code is at Here - - - - - 

</script>

</head>

The body of index.html

<body>
<div class="mainbody">

<h1 class="myheader">Test</h1>
<p>Test</p>

<ul class="drawers">

   <li class="drawer">
      <h2 class="drawer-handle open">Contact info</h2>
      <ul>

         <li>name
         </li>

         <li>
            <div class="">aaa
            </div>
         </li>
      </ul>
   </li>

   <li class="drawer">
      <h2 class="drawer-handle">Unpublished</h2>
      <ul>
         <li class="italic">
            <i>A</i> (2009).
         </li>
         <li class="italic">
            <i>aaa</i> (2008).
         </li>
      </ul>
   </li>     

   <li class="drawer">
      <h2 class="drawer-handle">Recent projects</h2>
      <ul>
         <li class="italic">
            Websites
         </li>

         <li class="italic">
            Search
            <form action="http://www.google.com/cse" id="cse-search-box">
            <div>
               <input type="hidden" name="cx" value="8834479:1qd7hky6khe" />
               <input type="hidden" name="ie" value="UTF-8" />
               <input type="text" name="q" size="31" />
               <input type="submit" name="sa" value="Search" />
            </div>
            </form>
            <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script>
         </li>

      </ul>
   </li>     

</ul>


</div>

</body>
</html>

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我的黑色迷你裙 2022-06-07 4 楼

I got the code to work in Firefox by replacing the following

<script type="text/javascript" src="jquery.js" /> 

to

<script type="text/javascript" src="jquery.js"></script>  
鱼忆七猫命九 2022-06-07 3 楼

Why are your tags in your jquery selectors in uppercase? By your doctype, you're using XHTML, and all tags must be lowercase. Not sure if that'll make a difference, but you should change H2 => h2, etc.

各空 2022-06-07 2 楼

My guess is that you have invalid HTML which causes some wrong DOM structure in Firefox. But it is hard to tell without looking at your code.

傲影 2022-06-07 1 楼

It works for me in Firefox 3.0.9

What exactly is not working?