亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于jQuery的$.getScript方法去加載javaScript文檔解析

 更新時(shí)間:2017年11月08日 09:43:32   作者:yangzailu1990  
下面小編就為大家?guī)?lái)一篇基于jQuery的$.getScript方法去加載javaScript文檔解析。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

1.兩個(gè)文件的代碼如下:

<script>
function Ajax(){  //將9-4.html中的Ajax()函數(shù)進(jìn)行修改
 $.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']也可寫(xiě)成comment.username
 html +="</table>"
//alert("Hello");
$("#target").html(html);
   }  
 );
}
</script>
<input type="button" value="Ajax提交" onclick="Ajax();" />
<div id="target"></div>

2.

3. 解析:

comments 是個(gè)數(shù)組
comment  是個(gè)對(duì)象。

comments是數(shù)組,具體來(lái)說(shuō)是json數(shù)組,而它的每個(gè)元素comment是json對(duì)象,并不是數(shù)組。既然是json對(duì)象,那么取值的方法有2種:comment.attribute或者comment['attribute']

comments 是個(gè)數(shù)組
comment 是個(gè)對(duì)象。
我也是這樣認(rèn)為的。

是不是對(duì)于json對(duì)象,引用其屬性有兩種方式,即comment.attribute或者comment['attribute']。

但是一般的對(duì)象,引用其屬性好像只能是comment.attribute這種形式吧。

我不知道對(duì)于json對(duì)象還可以這樣引用comment['attribute']。我以為這樣就是數(shù)組了。

這就是json區(qū)別于數(shù)組的地方,自有它的特殊性。

以上這篇基于jQuery的$.getScript方法去加載javaScript文檔解析就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論