Home > Web Front-end > JS Tutorial > Detailed explanation of jQuery's $.getScript method to load javaScript documents

Detailed explanation of jQuery's $.getScript method to load javaScript documents

小云云
Release: 2017-12-23 10:50:48
Original
2537 people have browsed it

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=&#39;1&#39; cellpadding=&#39;2&#39;>";
 $.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>
Copy after login

2.

##3. Analysis:

comments It is an array

comment is an object.

comments is an array, specifically a json array, and each element comment is a json object, not an array. Since it is a json object, there are two ways to get the value: comment.attribute or comment['attribute']

comments 是个数组
comment 是个对象。
我也是这样认为的。

是不是对于json对象,引用其属性有两种方式,即comment.attribute或者comment['attribute']。

但是一般的对象,引用其属性好像只能是comment.attribute这种形式吧。

我不知道对于json对象还可以这样引用comment['attribute']。我以为这样就是数组了。

这就是json区别于数组的地方,自有它的特殊性。
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template