Home  >  Article  >  Backend Development  >  Detailed explanation of Javascript calling XML to create linked drop-down box code examples

Detailed explanation of Javascript calling XML to create linked drop-down box code examples

黄舟
黄舟Original
2017-03-07 16:29:291200browse

Two methods are used to link drop-down boxes in traditional HTML pages:
1) Directly hardcode the content in the drop-down box into the javascript of html, and call the Javascript function to write it into the drop-down box in a loop. This method is not suitable for situations where the contents of the drop-down box change frequently. Because the data source and JavaScript program are written on the same page.



List




2) JavaScript reads the database directly, takes the records in the database and writes them into JavaScript, and then, like the first method, calls the JavaScript function to write to the drop-down box in a loop. This method separates the data source from JavaScript, but exposing the database connection has little practical value from a security perspective.


My method is to put the data in the drop-down box in an xml file, use javascript to read the XML file, and obtain the content in the drop-down box.

The HTML file is as follows:






在HTML中调用XML数据


类型 子类
account.xml 如下: Not Available dangdang1 dangdang2 dangdang3 dangdang4 dangdang5 dangdang6 zhuce_user1 zhuce_user2 tongxun

This method separates the data source from the javascript program and is suitable for frequently changing data sources. In xmlDoc.load, you can directly call URL parameters and read remote XML to achieve loose coupling. The above application passes in IE6.0. The disadvantage is that when removing the contents of the drop-down box list, you need to
repeat the deletion operation, otherwise there will be obvious bugs. I hope some readers can correct me.

The above is the detailed explanation of Javascript calling XML to create a linked drop-down box code example. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn