gpt4 book ai didi

javascript - jQuery 隐藏();和显示(); Internet Explorer 中的问题

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

我已经用 Internet Explorer 折腾了几个小时,似乎无法弄清楚我的问题。我正在尝试使用 jQuery show() 和 hide() 实现一个简单的“组选项切换器”。

您最好看一下我的演示以了解我的意思:http://softwaredb.org/test/jquery-multi-select.html

我的代码适用于除 IE 之外的所有浏览器。我的代码是这样的……

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Demo - Jquery Multi Select box</title>
<style type="text/css">
select{width:200px;height:200px;}
select#boysnames, select#girlsnames{display:none;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>

<body>
<div id="wrapper" style="padding:50px 0 0 50px;">

<form>
<select multiple="multiple" id="theoptions">
<option value="boysnames">Boys Names</option>
<option value="girlsnames">Girls Names</option>
</select>

<select multiple="multiple" id="placeholder">
</select>

<select multiple="multiple" id="boysnames">
<option>John</option>
<option>David</option>
<option>Tom</option>
</select>

<select multiple="multiple" id="girlsnames">
<option>Jenny</option>
<option>Amanda</option>
<option>Sara</option>
</select>
</form>
</div> <!-- end #wrapper -->

<script type="text/javascript">
$('option[value="boysnames"]').click(function() {
$('select#placeholder, select#girlsnames').hide();
$('select#boysnames').show();
});
$('option[value="girlsnames"]').click(function() {
$('select#placeholder, select#boysnames').hide();
$('select#girlsnames').show();
});
</script>

</body>
</html>

我的逻辑是...单击时,隐藏所有其他选择标签并显示我想看到的标签。它似乎工作正常,直到我在 IE 中尝试。任何想法我做错了什么?我对 jquery(和一般的 javascript/编程)还很陌生,如果这是一个愚蠢的问题,请原谅我。

最佳答案

不是跟踪选项级别的点击,而是跟踪选择级别的更改。

$('select#theoptions').change(function() {
$('#placeholder, #girlsnames').hide();
if($(this).val() == 'boysnames') {
$('#boysnames').show();
} else {
$('#girlsnames').show();
}
});

有很多方法可以使您的方法更直观一些,但这应该让您继续前进

关于javascript - jQuery 隐藏();和显示(); Internet Explorer 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14000323/

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