定义一个函数,创建HTML列表(arguments)

 1 function list(type) {
 2             var result = "<" + type + ">";
 3 
 4             // iterate through non-type arguments
 5             for (var i = 1; i < arguments.length; i++) {
 6                 result += "<li>" + arguments[i] + "</li>";
 7             }
 8 
 9             result += "</" + type + ">"; // end list
10 
11             return result;
12         }
13         var listHTML = list("ul", "One", "Two", "Three");
14         // listHTML is "<ul><li>One</li><li>Two</li><li>Three</li></ul>"
15         console.log(listHTML);

You can pass any number of arguments to this function

原文地址:https://www.cnblogs.com/qzsonline/p/2393309.html