Based on jQuery's $. getScript method to load javaScript file parsing, jquery. getscript

Source: Internet
Author: User

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.

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.