select1取决于select2 [英] select1 dependent on select2
问题描述
我有两个选择框,如国家和省。
当用户选择一个国家时,省份列表应该更改。
怎么可能去这样做?
Hi, I have two select boxes, like country and province.
When a user select a country the list of provinces should change.
How might one go about doing this?
推荐答案
Mark写道:
Mark wrote:
我有两个选择框,如国家和省。
当用户选择一个国家时,省份列表应该更改。
怎么可能这样做呢?
Hi, I have two select boxes, like country and province.
When a user select a country the list of provinces should change.
How might one go about doing this?
将onchange添加到select1,代码如下:
(它在IE7和Opera9中有效,但在FF2b中不起作用)
< html>
< head>
< / head>
< body> ;
< select id =" select1" onchange =" select1_change();">
< option> aaa< / option>
< option> bbb< / option>
< / select>
< select id =" select2">
< option> xxx< / option>
< / select>
< script>
//将onchange添加到select1,这样写:
function select1_change( )
{
var select2 = document.getElementById(" select2");
for(var i = 0; i< select2 .options.length; i ++)
{
select2.options.remove(i);
}
select2.options.add(新选项(hello,1));
}
< / script>
< / body>
< / html>
add onchange to select1, codes like this:
(it worked in IE7 and Opera9, BUT it not worked in FF2b)
<html>
<head>
</head>
<body>
<select id="select1" onchange="select1_change();">
<option>aaa</option>
<option>bbb</option>
</select>
<select id="select2">
<option>xxx</option>
</select>
<script>
//add onchange to select1, write like this:
function select1_change()
{
var select2 = document.getElementById("select2");
for (var i = 0; i < select2.options.length; i++)
{
select2.options.remove(i);
}
select2.options.add(new Option("hello", "1"));
}
</script>
</body>
</html>
jh ***** @ gmail.com 写道:
Mark写道:
Mark wrote:
H.我,我有两个选择框,如国家和省。
当用户选择一个国家时,省份列表应该更改。
怎么可能这样做?
Hi, I have two select boxes, like country and province.
When a user select a country the list of provinces should change.
How might one go about doing this?
将onchange添加到select1,代码如下:
(它在IE7和Opera9中工作,但它在FF2b中不起作用)
< html>
< head>
< / head>
< body> ;
< select id =" select1" onchange =" select1_change();">
< option> aaa< / option>
< option> bbb< / option>
< / select>
< select id =" select2">
< option> xxx< / option>
< / select>
< script>
//将onchange添加到select1,这样写:
function select1_change( )
{
var select2 = document.getElementById(" select2");
for(var i = 0; i< select2 .options.length; i ++)
{
select2.options.remove(i);
}
select2.options.add(新选项(hello,1));
}
< / script>
< / body>
< / html>
add onchange to select1, codes like this:
(it worked in IE7 and Opera9, BUT it not worked in FF2b)
<html>
<head>
</head>
<body>
<select id="select1" onchange="select1_change();">
<option>aaa</option>
<option>bbb</option>
</select>
<select id="select2">
<option>xxx</option>
</select>
<script>
//add onchange to select1, write like this:
function select1_change()
{
var select2 = document.getElementById("select2");
for (var i = 0; i < select2.options.length; i++)
{
select2.options.remove(i);
}
select2.options.add(new Option("hello", "1"));
}
</script>
</body>
</html>
嗯...我想知道为什么它在firefox中不起作用?那好吧。这应该是足够让我开始的
。非常感谢!
hmm... i wonder why it doesn''t work in firefox? oh well. this should be
enough to get me started. thanks a ton!
因为这些代码不遵循DOM标准。
because these code is not follow the DOM standard.
这篇关于select1取决于select2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!