gpt4 book ai didi

javascript - 过滤安全 Qs 下拉列表

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

首先:标题应该是“过滤安全问题”下拉列表,但显然,我不能在标题中使用“问题”或“问题”一词。

我正在寻找at this code example但它似乎不再有效了。有人知道为什么以及如何解决它吗?

我想过滤安全问题,这样如果我从问题列表中选择问题,对于下一个问题,我将不再在安全问题列表中看到问题。这是为了防止重复选择安全问题。

以下是链接中的示例副本:

<!DOCTYPE html>
<html">
<head>
<meta charset="utf-8" />
<title>CSS Newbie Example: Filtering Select Boxes</title>
<link rel="stylesheet" type="text/css" href="select.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function () {
$('.security').change(function () {
$('.security option').show(0);
$('.security option:selected').each(function () {
oIndex = $(this).index();
if (oIndex > 0) {
$('.security').each(function () {
$(this).children('option').eq(oIndex).not(':selected').hide(0);
});
}
});
});
$('.security').change();
});
</script>
</head>
<body>
<div id="wrap">
<h1>Intelligent Filtering of Select Boxes</h1>
<p>The following three select boxes contain the same options. But once you've selected one of the options from one select box, that item is removed from the subsequent boxes, preventing duplicate selections. <a href="http://www.cssnewbie.com/intelligent-select-box-filtering/">Return to the original article.</a></p>
<h2>Select Your Security Questions:</h2>
<p>
<select class="security" name="security1">
<option value="0">Select a question from the following options.</option>
<option value="1">Who's your daddy?</option>
<option value="2">What is your favorite color?</option>
<option value="3">What is your mother's favorite aunt's favorite color?</option>
<option value="4">Where does the rain in Spain mainly fall?</option>
<option value="5">If Mary had three apples, would you steal them?</option>
<option value="6">What brand of food did your first pet eat?</option>
</select>
</p>
<p>
<select class="security" name="security2">
<option value="0">Select a question from the following options.</option>
<option value="1">Who's your daddy?</option>
<option value="2">What is your favorite color?</option>
<option value="3">What is your mother's favorite aunt's favorite color?</option>
<option value="4">Where does the rain in Spain mainly fall?</option>
<option value="5">If Mary had three apples, would you steal them?</option>
<option value="6">What brand of food did your first pet eat?</option>
</select>
</p>
<p>
<select class="security" name="security3">
<option value="0">Select a question from the following options.</option>
<option value="1">Who's your daddy?</option>
<option value="2">What is your favorite color?</option>
<option value="3">What is your mother's favorite aunt's favorite color?</option>
<option value="4">Where does the rain in Spain mainly fall?</option>
<option value="5">If Mary had three apples, would you steal them?</option>
<option value="6">What brand of food did your first pet eat?</option>
</select>
</p>
</div>
</body>
</html>

最佳答案

该页面出了点问题。查看源代码可以看到 <script>标签被转义并呈现为 &lt;script&gt; 。这对于显示示例之外的源代码来说很好,但页面上没有该代码的实际副本。因此,在这个“实时”示例中,任何 JS 都不会按照您的预期运行。除此之外,这工作正常。这是JSFiddle使用相同的代码。

// -- works fine
$(function () {
$('.security').change(function () {
$('.security option').show(0);
$('.security option:selected').each(function () {
oIndex = $(this).index();
if (oIndex > 0) {
$('.security').each(function () {
$(this).children('option').eq(oIndex).not(':selected').hide(0);
});
}
});
});
$('.security').change();
});

此外,查看一些评论...

This does not work in an IE browser, safari, or chrome.


Hm… doesn’t work in Google Chrome on Mac OS X…

让人相信该网站有些东西误入歧途。有趣的是,在 FF 中运行它确实有效。 Chrome 和 IE 都崩溃了。

关于javascript - 过滤安全 Qs 下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30673768/

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