我是Java脚本的新手.在这里,我有2个下拉小提琴的工作示例.
HTML:
<select id=a></select>
<select id=b></select>
<select id=c></select>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
var data = [ // The data
['ten', [
'eleven','twelve'
]],
['twenty', [
'twentyone', 'twentytwo'
]]
];
$a = $('#a'); // The dropdowns
$b = $('#b');
for(var i = 0; i < data.length; i++) {
var first = data[i][0];
$a.append($("<option>"). // Add options
attr("value",first).
data("sel", i).
text(first));
}
$a.change(function() {
var index = $(this).children('option:selected').data('sel');
var second = data[index][2]; // The second-choice data
$b.html(''); // Clear existing options in second …Run Code Online (Sandbox Code Playgroud)