The given code is an HTML document with some JavaScript code. The JavaScript code is incomplete and needs to be modified to sort the movie box office values and display the corresponding movie names and box office values in the table.

Here is the modified JavaScript code:

//电影数组
var movieArr = ['隐秘而伟大', '八佰', '疯狂动物城', '头师傅一体'];
//电影票房数组
var boxofficeArr = [14.7, 33.9, 12, 15.3];

//将电影名称和票房值合并为一个数组
var movieBoxOfficeArr = [];
for (var i = 0; i < movieArr.length; i++) {
    movieBoxOfficeArr.push({
        movie: movieArr[i],
        boxOffice: boxofficeArr[i]
    });
}

//根据票房值对数组进行排序,由小到大排序
movieBoxOfficeArr.sort(function(a, b) {
    return a.boxOffice - b.boxOffice;
});

//在页面输出内容
var table = document.querySelector("table");
for (var i = 0; i < movieBoxOfficeArr.length; i++) {
    var row = table.insertRow();
    var rankCell = row.insertCell();
    var movieCell = row.insertCell();
    var boxOfficeCell = row.insertCell();
    rankCell.innerHTML = i + 1;
    movieCell.innerHTML = movieBoxOfficeArr[i].movie;
    boxOfficeCell.innerHTML = movieBoxOfficeArr[i].boxOffice;
}

This code will sort the movie box office values in ascending order and display the corresponding movie names and box office values in the table

!DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 titleTitletitle style tabletrtd border 1px solid black; border-collapse collapse; table

原文地址: https://www.cveoy.top/t/topic/iHy7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录