源代码适用于Chrome,不适用于Firefox和IE [英] Sourcecode Works for Chrome, not for Firefox and IE

查看:123
本文介绍了源代码适用于Chrome,不适用于Firefox和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络开发的新手。



如果我使用地址www.xxxxxx.com/test.html#chgd,第二支手风琴应该正在扩大。它适用于Chrome,但不适用于Firefox和资源管理器。



源代码中有什么问题适用于Chrome而不适用于Firefox和资源管理器?



我也使用'window.location.hash;'但不幸的是,同样的问题也出现了。



谢谢!





I'm newbie in web development.

If I use the adress "www.xxxxxx.com/test.html#chgd", the second accordion should be expanding. It works perfectly for Chrome but not for Firefox and Explorer.

What is the problem in the source code that works for Chrome but not for Firefox and Explorer?

I also have used 'window.location.hash;' but unfortunately, same problem occur.

Thanks!


<pre lang="xml"><!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <link href="C:\Users\h\Desktop\test\bootstrap-theme.css" rel="stylesheet"/>
        <link href="C:\Users\h\Desktop\test\bootstrap.css" rel="stylesheet"/>


        <script src="C:\Users\h\Desktop\test\jquery-1.11.2.min.js"></script>
    <script src="C:\Users\h\Desktop\test\bootstrap.min.js"></script>
    <script>

    jQuery(document).ready(function() {
        var url = = document.location.toString();
        if ( url.match('#') ) {
            var hash = url.split('#')[1];

            // collapse the expanded panel
            $('#accordion .accordion-collapse').removeClass('in');

            // expand the requested panel
            $('#' + hash + '_c').addClass('in');
        }
    });
    </script>
    </head>


<body>



          <div id="accordion" class="accordion-group">
                <div class="panel">
                    <h4 id="cs" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#cs_c">Child Survival: Boosting Immunity and Managing Diarrhoea</a></h4>
                    <div id="cs_c" class="accordion-collapse collapse in">
                        <p>...</p>
                    </div>

                    <h4 id="chgd" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#chgd_c">Child Health, Growth and Development: Preventing Mental Impairment with Iodine and Iron</a></h4>
                    <div id="chgd_c" class="accordion-collapse collapse">
                        <p>...</p>
                    </div>

                    <h4 id="wmnh" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#wmnh_c">Women’s and Newborn Survival and Health: Iron Supplementation and Food Fortification</a></h4>
                    <div id="wmnh_c" class="accordion-collapse collapse">
                        <p>...</p>
                    </div>
                </div>
            </div>



</body>
</html>

推荐答案

(< span class =code-string>' #accordion .accordion-collapse')。removeClass(' in');

// 展开请求的面板
('#accordion .accordion-collapse').removeClass('in'); // expand the requested panel


' #' + hash + ' _ c')。addClass(' in' );
}
});
< / script >
< / head >


< 正文 >



< div id = accordion < span class =code-attribute> class
= accordion-group >
< div class = panel >
< h4 id = cs class = accordion-title > < a data-toggle = collapse data-parent = #accordion data-target = #cs_c > 儿童生存:提高免疫力和控制腹泻< / a > < / h4 >
< div id = cs_c class = >
< p < span class =code-keyword>> ... < / p >
< / div >

< h4 id = chgd class = accordion-title > < a data-toggle = collapse data-parent = #accordion data-target = #chgd_c > 儿童健康,成长与发展:用碘和铁预防精神障碍< / a > < / h4 >
< div id = chgd_c class = 折叠折叠崩溃 >
< p > ... < / p >
< / div >

< < span class =code-leadattribute> h4 id = wmnh class = accordion-title > < a data-toggle = 折叠 data-parent = #accordion data-target = #wmnh_c > 女性和新生儿的生存和健康:补铁和食物强化< / a > < / h4 >
< div id = wmnh_c class = 手风琴折叠崩溃 >
< p > ... < / p >
< / div >
< / div >
< / div >



< / body >
< / html >
('#' + hash + '_c').addClass('in'); } }); </script> </head> <body> <div id="accordion" class="accordion-group"> <div class="panel"> <h4 id="cs" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#cs_c">Child Survival: Boosting Immunity and Managing Diarrhoea</a></h4> <div id="cs_c" class="accordion-collapse collapse in"> <p>...</p> </div> <h4 id="chgd" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#chgd_c">Child Health, Growth and Development: Preventing Mental Impairment with Iodine and Iron</a></h4> <div id="chgd_c" class="accordion-collapse collapse"> <p>...</p> </div> <h4 id="wmnh" class="accordion-title"><a data-toggle="collapse" data-parent="#accordion" data-target="#wmnh_c">Women’s and Newborn Survival and Health: Iron Supplementation and Food Fortification</a></h4> <div id="wmnh_c" class="accordion-collapse collapse"> <p>...</p> </div> </div> </div> </body> </html>


这些路径C:\ Users \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ $ b你应该托管你的网站。这是因为javascript在沙盒中运行,不应该直接访问客户端的文件系统。



你首先要做的就是让他们来自CDN。



替换jquery网址用; https://code.jquery.com/ui/1.11.4/jquery-ui。 min.js [ ^ ]



和引导程序一起;



//maxcdn.bootstrapcdn.com/ bootstrap / 3.3.4 / js / bootstrap.min.js



那么它应该可以工作。



但是最好在你的计算机上安装IIS。

我不知道你正在运行什么版本的Windows,但在google上搜索在Windows上安装iis ....应该得到你在那里。

这个过程非常简单。
These paths "C:\Users\h\Desktop\test\" are the problem.

You're not allowed by most browsers to do this.
You're website should be hosted. This is because javascript is running in a 'sandbox' and should not have direct access to the client's filesystem.

The thing you could do first is have them come from a CDN.

replace the jquery url with; https://code.jquery.com/ui/1.11.4/jquery-ui.min.js[^]

And the bootstrap with;

//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js

Then it should work.

However it is better to install IIS on you're computer.
I don't know what version of Windows you're running, but searching on google for install iis on windows.... should get you there.
The process is pretty straight forward.


这篇关于源代码适用于Chrome,不适用于Firefox和IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆