根据javascript中的数组列表进行选择 [英] Selection based on array list in javascript
本文介绍了根据javascript中的数组列表进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
lt;亲爱的先生/女士,>
我是Java脚本的新手
我有两组列表,其中一个用于男性列表(父亲,兄弟,儿子),另一个用于女性列表(母亲,女儿,姐姐),如果我选择父亲,则下拉列表将显示男性,如果我选择母亲,则列表将显示女
提供一些示例代码
您能给一些指导以继续进行吗?.
在此先感谢
问候
Sankar
lt;Dear Sir / Madam ,>
I am new to java-script
I have two set of lists one for male list(father,brother,son) and another for female list(mother,daughter,sister) , if i select father the drop-down will show male ,if i select mother then it will be female
Provide some sample codes
Can you give some guidelines to proceed..
Thanks in Advance
Regards
Sankar
推荐答案
下面是一个快速示例:
Here''s a quick sample:
<!DOCTYPE html>
<html>
<head>
<script>
function onListChange(list)
{
var option = parseInt(list.value), message;
if (option == 0)
message = 'Neither';
else
message = list.getAttribute('id');
document.getElementById('genderTarget').innerHTML = message;
}
</script>
</head>
<body>
<select id='Male' onchange='onListChange(this)'>
<option value='0'>-Select a Male-</option>
<option value='1'>Father</option>
<option value='2'>Brother</option>
<option value='3'>Son</option>
</select>
<select id='Female' onchange='onListChange(this)'>
<option value='0'>-Select a Female-</option>
<option value='1'>Mother</option>
<option value='2'>Sister</option>
<option value='3'>Daughter</option>
</select>
<br>
Gender of last selection: <span id='genderTarget'></span>
</body>
<html>
尝试一下..
Try this..
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
var maleoptions=['father','brother','son'];
var femaleoptions=['mother','daughter','sister'];
function AddMaleOptions()
{
if(
(#male").attr("checked")) {
("#male").attr("checked")) {
这篇关于根据javascript中的数组列表进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文