源代码适用于Chrome,不适用于Firefox和IE

编程入门 行业动态 更新时间:2024-10-15 08:26:08
本文介绍了源代码适用于Chrome,不适用于Firefox和IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是网络开发的新手。 如果我使用地址www.xxxxxx/test.html#chgd,第二支手风琴应该正在扩大。它适用于Chrome,但不适用于Firefox和资源管理器。 源代码中有什么问题适用于Chrome而不适用于Firefox和资源管理器? 我也使用'window.location.hash;'但不幸的是,同样的问题也出现了。 谢谢!

I'm newbie in web development. If I use the adress "www.xxxxxx/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>

推荐答案

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

(' #' + hash + ' _ c')。addClass(' in' ); } }); < / script > < / head > < 正文 > < 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 > 儿童生存:提高免疫力和控制腹泻< / a > < / h4 > < div id = cs_c class = > < p > ... < / 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 > < 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网址用; code.jquery/ui/1.11.4/jquery-ui。 min.js [ ^ ] 和引导程序一起; //maxcdn.bootstrapcdn/ 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; code.jquery/ui/1.11.4/jquery-ui.min.js[^] And the bootstrap with; //maxcdn.bootstrapcdn/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

本文发布于:2023-11-26 11:22:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633797.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   源代码   不适用于   Chrome   Firefox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!