gpt4 book ai didi

javascript - 在窗口加载时创建显示隐藏功能?

转载 作者:行者123 更新时间:2023-11-30 17:12:01 26 4
gpt4 key购买 nike

我正在使用有人在 stackoverflow 上协助我编写的脚本。它工作得很好,但是它不适用于我在 IE8-10 中的 amchart(我也用 amcharts 记录了这个问题,因为问题似乎与图表有关)。

我想同时使用 jQuery 脚本对自己进行进一步的故障排除。我仍在学习 jQuery,需要一些指导来将以下 javascript 代码转换为 jQuery show() hide() 脚本。

我试过它的基本形式:

$(window).load(function() {
$("div").hide();
};

它在除 IE 8-10 之外的所有其他浏览器中工作,当您切换表格时图表不显示。下面请看两个在 IE 8-10 中有效的脚本的摘录。

<script type="text/javascript">

function chart1() {
var show = ['chartdiv1', 'unit-price'];
for ( var i = 0; i < show.length; ++i )
document.getElementById(show[i]).style.display = "block";
var hide = ['chartdiv2', 'unit-price-value','chartdiv3', 'unit-price-rand'];
for ( var i = 0; i < hide.length; ++i )
document.getElementById(hide[i]).style.display = "none";
};

</script>

<script>
function chart1() {
document.getElementById("chartdiv1").style.display = "block";
document.getElementById("unit-price").style.display = "block";
};
function chart2() {
document.getElementById("chartdiv2").style.display = "none";
document.getElementById("unit-price-value").style.display = "none";
};
function chart3() {
document.getElementById("chartdiv3").style.display = "none";
document.getElementById("unit-price-rand").style.display = "none";
};
</script>


</head>
<body style="background-color:#FFFFFF; margin: 10px;" onLoad="chart1()"> or onload"chart1(), chart2(),.............

最佳答案

您的代码中似乎存在语法错误。

函数不应该是这样的吗? :

$(window).load(function() {
$("div").hide(); //and not $("div">.hide();
}); // added the closing bracket of load function

关于javascript - 在窗口加载时创建显示隐藏功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26795728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com