如何设置选择框或下拉列表框的值,因为已设置了上一个列表框的值 [英] How to set values for select box or drop down list box as the previous list box value is set

查看:110
本文介绍了如何设置选择框或下拉列表框的值,因为已设置了上一个列表框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用jQuery来更改第二选择基于第一个选择列表选项的列表

Possible Duplicate:
Use jquery to change second select list based on first select list option

我的代码中有两个选择元素.一个用于州(#us_state),第二个用于城市(#city_name).当我选择州"时,第二个选择元素必须仅包含在选定州中存在的城市.

I've got two select elements in my code. One for states (#us_state) and second for cities (#city_name). When I choose a "state" the second select element must contain only that cities which exists in selected state.

推荐答案

使用jquery append附加选项值(还请记住使用

use jquery append to append the option values (also remember to clear the options outside the iterating loop using

$('#city_name').html("");

$('#city_name').append('<option value="'+city+'">'+city+'</option>');

这篇关于如何设置选择框或下拉列表框的值,因为已设置了上一个列表框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆