1. The code for two files is as follows:
<Script>functionAjax () {//To Modify the Ajax () function in 9-4.html$.getscript ('9-8.js',function(data) {varHTML="<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 in Comment.username HTML+="</table>"//alert ("Hello");$("#target"). HTML (HTML); }
);}</Script><inputtype= "button"value= "Ajax Commit"onclick= "Ajax ();" /><DivID= "Target"></Div>
2.
3. Analysis:
Comments is a number group
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 2 ways to take the value: Comment.attribute or comment[' attribute ']
Comments is an array comment is an object. I think so, too.
There are two ways to refer to a JSON object, which is Comment.attribute or comment[' attribute '). But a generic object, referencing its properties, seems to be the only form of Comment.attribute. I do not know that for JSON objects you can also refer to comment[' attribute '. I thought it was an array. This is where JSON differs from the array and has its own particularity.
jquery's $.getscript method to load JavaScript document parsing