jquery's $.getscript method to load JavaScript document parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.