为什么跟随Jquery代码在IE和Chrome中工作但在Safari中不起作用?

时间:2011-07-19 21:28:20

标签: jquery

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>testsasfa</title>
        <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
        </script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">
        </script>
        <script src='http://code.jquery.com/jquery-git.js' type='text/javascript'>
        </script>
        <script src='http://media.lib.byu.edu/js/jquery/plugins/jquery.livequery-1.0.3.js' type='text/javascript'>
        </script>
        <style type='text/css'>

            .general {
                display: none;
            }

            .show {
                display: block;
            }

            .title {
                background-color: #0099CC;
                font-size: 30px;
                color: white;
            }

            .subtitle {
                font-style: italic;
            }

            textarea {
                height: 70px;
                width: 890px;
            }
        </style>
        <script type='text/javascript'>
            jQuery.noConflict();
            $(function(){
                $('#generalTitle').click(function(e){
                    e.preventDefault();
                    $('.general').toggleClass("show");
                });
            });
        </script>
    </head>
    <body>
        <table>
        <tr>
            <td id='generalTitle' class='title'>
                General Information
            </td>
        </tr>
        <tr>
            <td>
                <table class="general">
                    <tr class='subtitle'>
                        <td>
                            Definition
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <textarea id="div1">
                            </textarea>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        </table>
    </body>
</html>

2 个答案:

答案 0 :(得分:6)

    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript">
    </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js">
    </script>
    <script src='http://code.jquery.com/jquery-git.js' type='text/javascript'>
    </script>

你包括jQuery三次。这是一团糟。

你显然不知道你在做什么。去购买一本网页开发书。或者至少阅读MDN

答案 1 :(得分:0)

如果您致电jQuery.noConflict(),那么您不应该(应该不能)使用$选择器,除非您将其范围包括在内:

jQuery.noConflict();
//scope it
(function($){
  // you can now use $ to access jQuery in here only.
})(jQuery);