【发布时间】:2011-07-21 07:09:37
【问题描述】:
我一直在寻找类似的问题,但它们与我正在寻找的有点不同。
基本上,这就是我的目标:
有一个填充值的第一个下拉列表,例如:
<form>
<select id="tags" name="tags">
<option value="agent" selected="selected">agent</option>
<option value="extension">extension</option>
<option value="fileversion" >fileversion</option>
<option value="pages">pages</option>
</select>
然后,在第二个下拉列表中,根据所选内容显示选项,例如,如果选择了代理,则运算符将为 = 或 !=,因为它是文本。对于文件版本,将有 4 个操作数,=、!=、> 和 <。
最后,会有第三个下拉菜单,其值也取决于最初选择的选项。
For example, when agent is selected, the options would be pdf, word, excel, ppt etc. and others it would just be a text box to type in rather than exhaust all possible价值观。
最后这将用于搜索数据库,但它是一个大数据库,搜索速度太慢,所以我认为选项的值将存储在数组中,而不是直接拉取。
如您所见,这相当棘手:/ 非常感谢任何帮助。
谢谢, 马丁
编辑:
为那些碰巧正在寻找相同答案的人找到答案:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="js/dropdown.js"></script>
</head>
<body>
<form>
<select id="tags" name="tags">
<option value="tags" selected="selected">tags</option>
<option value="agent">agent</option>
<option value="extension">extension</option>
</select>
<select name="operands">
<option>operands</option>
</select>
</form>
</body>
</html>
dropdown.js:
$(document).ready(function() {
$tags = $("select[name='tags']");
$operands = $("select[name='operands']");
$tags.change(function() {
if ($(this).val() == "agent") {
$("select[name='operands'] option").remove();
$("<option>=</option>").appendTo($operands);
$("<option>!=</option>").appendTo($operands);
}
if ($(this).val() == "extension")
{
$("select[name='operands'] option").remove();
$("<option>.pdf</option>").appendTo($operands);
$("<option>.doc</option>").appendTo($operands);
}
if ($(this).val() == "tags")
{
$("select[name='operands'] option").remove();
$("<option>operands</option>").appendTo($operands);
}
});
});
【问题讨论】:
标签: php jquery html arrays drop-down-menu