我正在尝试使用 jQuery 执行一个简单的隐藏功能,它在 IE10 中运行良好,但在 Firefox (25.0.1) 中不起作用。设置基本上如下:我有一个带有内容 block 和按钮的基本 HTML 页面。单击该按钮应将 html 从另一个(本地)页面加载到内容 block 中,但某些部分(在本例中为“描述”类的 div)应被隐藏。这是代码:
基本 HTML 页面:
<!DOCTYPE html>
<html>
<head>
<title>Test for jQuery Hide function in Firefox</title>
<link rel="stylesheet" type="text/css" href="main.css">
<script type="text/javascript" src="../jquery.min.js"></script>
<script type="text/javascript" src="hide.js"></script>
</head>
<body>
<div id="contentblock">This is where the content goes</div>
<div id="button">Button</div>
</body>
</html>
要加载的 HTML:
<!DOCTYPE html>
<html>
<head>
<title>Test 2</title>
</head>
<body>
<div class="step">
<div class="stepcontent">This is the second file, first div</div>
<div class="description">Description #1</div>
</div>
<div class="step">
<div class="stepcontent">This is the second file, second div</div>
<div class="description">Description #2</div>
</div>
<div class="step">
<div class="stepcontent">This is the second file, second div</div>
<div class="description">Description #3</div>
</div>
</body>
</html>
jQuery:
$(document).ready(function(){
$('#button').click(function(){
$('#contentblock').load( 'loadfile.html' );
$('.description').hide();
});
});
同样,上面的代码在 IE10 中可以正常工作,但在 Firefox 中却不行。我现在无法在 Chrome 中检查它,因为 Chrome 不允许将本地存储的 HTML 加载到另一个 HTML 页面中。 提前感谢您提供的任何帮助。
最佳答案
要允许 firefox 加载本地文件(这可能是您的脚本暂停的地方),请通过在地址栏中键入“about:config”来访问 firefox 配置。
搜索“origin”并将“security.fileuri.strict_origin_policy”设置为 false。
关于jQuery 隐藏功能在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21253221/