Home >Web Front-end >JS Tutorial >Detailed explanation of jQuery's $.getScript method to load javaScript documents
This article mainly brings you an article based on jQuery's $.getScript method to load javaScript document parsing. The editor thinks it is quite good, so I will share it with you now and give it as a reference. I hope it can help everyone.
1. The codes of the two files are as follows:
<script> function Ajax(){ //将9-4.html中的Ajax()函数进行修改 $.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']也可写成comment.username html +="</table>" //alert("Hello"); $("#target").html(html); } ); } </script> <input type="button" value="Ajax提交" onclick="Ajax();" /> <p id="target"></p>
2.
##3. Analysis: comments It is an arraycomment is an object.
comments 是个数组 comment 是个对象。 我也是这样认为的。 是不是对于json对象,引用其属性有两种方式,即comment.attribute或者comment['attribute']。 但是一般的对象,引用其属性好像只能是comment.attribute这种形式吧。 我不知道对于json对象还可以这样引用comment['attribute']。我以为这样就是数组了。 这就是json区别于数组的地方,自有它的特殊性。Related recommendations:
javaScript and jQuery implement automatic loading
javascript loads and runs js method in order_javascript skills
jQuery loads an html page into the specified div
The above is the detailed content of Detailed explanation of jQuery's $.getScript method to load javaScript documents. For more information, please follow other related articles on the PHP Chinese website!