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

mac2022-06-30  29

 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/archive/2012/03/13/2393309.html

最新回复(0)