Based on jQuery's $. getScript method to load javaScript file parsing, jquery. getscript
1. The code for the two files is as follows:
<Script> function Ajax () {// modify the Ajax () function in 9-4.html $. getScript ('9-8. js', function (data) {var html = "<table border = '1' cellpadding = '2'>"; $. each (comments, function (Index, comment) {html + = '<tr> <td>' + comment. username + ': </td> <td>' + comment ['content'] + '</td> </tr> ';}) // comment ['username'] can also be written as comment. username html + = "</table>" // alert ("Hello"); $ ("# target" target .html (html );});} </script> <input type = "button" value = "Ajax submit" onclick = "Ajax ();"/> <div id = "target"> </div>
2.
3. Resolution:
Comments is an array.
Comment is an object.
Comments is an array, specifically a json array, and each of its elements comment is a json object, not an array. Since it is a json object, there are two methods for value: comment. attribute or comment ['attribute']
Comments is an array. comment is an object. I think so too. Whether the attribute of a json object can be referenced in two ways: comment. attribute or comment ['attribute']. However, for a common object, it seems that its attribute can only be in the form of comment. attribute. I don't know whether comment ['attribute'] can be referenced in json objects. I thought it was an array. This is the difference between json and array. It has its own particularity.
The above $. getScript Method Based on jQuery to load javaScript document Parsing is all the content shared by xiaobian. I hope you can give us a reference and support more.