根据第一个下拉列表选择,第二个下拉列表应包含相关内容 [英] Depending on first drop list selection, second drop down list should contain related contents

查看:45
本文介绍了根据第一个下拉列表选择,第二个下拉列表应包含相关内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据第一个下拉列表项的选择,我希望第二个下拉列表应包含相关内容.我怎么能在java中做到这一点?例如,假设,第一个下拉列表包含国家名称,第二个下拉列表包含国家名称.如果我选择一个特定的国家,比如印度",从第一个下拉列表中命名,那么第二个列表应该只显示相关国家,即印度".两个列表都是动态的.

Depending on first drop down list item selection, i want a second drop down list should contain related contents. How can i do this in java? For instance, Let say, first Drop down list contains a name of countries, and second drop down list contains the names of states. And if i select a particular country, say "India", name from a first drop down list then second list should show only related states of country i.e states of "India". And both lists are dynamic.

推荐答案

我建议为此使用 javascript:

I would recommend using javascript for this:

  • 使用 ajax,通过执行返回选项的 struts 操作,并重新加载您的 select 内容,例如使用 jquery:

  • either with ajax, by making a struts action that returns the options, and reload your select content, for example with jquery:

$("#stateSelect").load('http://host/myStateAction.do?country=' + country);

或在页面加载时加载整个国家/州映射,并使用纯 javascript 更新第二个列表,无需服务器调用.为此,您可以例如在每个国家/地区存储 option 一个 data-states 属性,其中包含相应的状态.

or loading the whole country/state mapping on page load, and update the second list with pure javascript with no server call. To do this you can for example store in each country option a data-states attributes, containing the corresponding states.

否则,如果您想避免使用javascript,您可以在触发更改事件时提交表单,并在服务器端(struts 操作)根据第一个值填充第二个列表,然后重定向到表单页.

发送“验证码”获取 | 15天全站免登陆