How to use JavaScript to realize a two-level linkage drop-down box
This article mainly explains "how to use JavaScript to achieve a two-level linkage drop-down box", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use JavaScript to achieve a two-level linkage drop-down box" bar!
Javascript is a case-sensitive client scripting language for object-oriented dynamic types, which is developed from Netscape's LiveScript. The main purpose is to solve the speed problem left over by server-side languages, such as Perl, and to provide customers with smoother browsing results.
Display code printing
New Document / / defines a two-dimensional array of cities in the same order as the provinces. Obtain the corresponding city array var city= ["Beijing", "Tianjin", "Shanghai", "Chongqing"], ["Nanjing", "Suzhou", "Nantong", "Changzhou"], ["Fuzhou", "Fu'an", "Longyan", "Nanping"], [Guangzhou "," Chaoyang "," Chaozhou "," Chenghai "], [Lanzhou"]. "Baiyin", "Dingxi", "Dunhuang"] Function getCity () {/ / get the object of the province drop-down box var sltProvince=document.form1.province; / / get the city drop-down box object var sltCity=document.form1.city; / / get the city array var provinceCity=city of the corresponding province [sltProvince.selectedIndex-1]; / / clear the city drop-down box, leaving only the prompt option sltCity.length=1; / / populate the city drop-down box with the values in the city drop-down box for (var icities 0 countries I