Home > Article > Backend Development > Detailed explanation of Javascript calling XML to create linked drop-down box code examples
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:
account.xml 如下:在HTML中调用XML数据
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)!