添加标题并仅提取评级

时间:2015-04-16 21:10:43

标签: javascript json parsing

我想为标题添加标题h2。

  1. 如何在点击电影的thumnails时获取h2标签上的电影标题?我希望在点击相关电影时获得关于电影的评分和一些信息。如果我是另一部电影,评级和一些信息应该会消失
  2. 如何获得电影的评级和描述?
  3. 我想要一张电影的海报?
  4. 代码      

     <div class="row">
       <div class="span12">
        <h1 class="page-header"> Best Videos Ever ❤</h1>
       </div>
     </div>
    
     <div class="row">
       <div class="span3">
         <ul id="videos-list">
        </ul>
       </div>
       <div class="span9" id="video-watcher">
       </div>
     </div>
     </div>
    
    <script type="text/javascript" src="json.js"></script>
    <script type="text/javascript" src="js.js"></script>
    <script>
    
    
    var videos = [
     {"youtubeId": "QHWbzrCJ4nE",
       "title": "Chappie",
    "data": "http://www.omdbapi.com/?t=chappie&y=&plot=short&r=json"
     },
     {"youtubeId": "5Yab0sXGEjg",
       "title": "Furious 7",
    
    "data": "http://www.omdbapi.com/?t=furious+7&y=&plot=short&r=json"
     },
     {"youtubeId": "8ztAypW5MRE",
       "title": "Runner",
    "data": "http://www.omdbapi.com/?t=runner&y=&plot=short&r=json"
    
     },
     {"youtubeId": "SfZWFDs0LxA",
       "title": "Fifty Grey of Shades",
    "data": "http://www.omdbapi.com/?=Fifty+shades+of+Grey&y=&plot=short&r=json"
     }
    
    ];
    
    
    
    var addVideoToList = function(video) {
    
       var videoLink = $('<a>');
    
       videoLink.append(video.title);
    
    
       var thumbnailUrl = youtube.generateThumbnailUrl(video.youtubeId);
           var thumbnailImg = $('<img>');
           thumbnailImg.attr('src', thumbnailUrl);
           videoLink.append(thumbnailImg);
    
           videoLink.on('click', function(e) {
               e.preventDefault();
    
    
    
    
    
    
            $.getJSON(video.data, function(data) {
    
                     var items = [];
                        $.each( data, function( key, val ) {
                        items.push( "<li id='" + key + "'>" + val + "</li>" );
                        });
                        $( "<ul/>", {
                        "class": "my-new-list",
    
                        html: items.join( "" )
    
                        }).appendTo( "body" );
    
    
    
                });
    
    
               var videoEmbed = $('<iframe></iframe>');
    
               videoEmbed.attr('src', youtube.generateEmbedUrl(video.youtubeId));
               videoEmbed.attr('width', 560);
               videoEmbed.attr('height', 315);
    
               var videoWatcher = $('#video-watcher');
               videoWatcher.hide();
    
           videoWatcher.html(videoEmbed);
           videoWatcher.fadeIn();
       });
    
       var videoItem = $('<li>');
       videoItem.append(videoLink);
       $('#videos-list').append(videoItem);  }
    
    for (var i = 0; i < videos.length; i++) {
       addVideoToList(videos[i]);  }    
    </script>
    

0 个答案:

没有答案