日期:2014-05-16 浏览次数:20394 次
/** * function join(seperator) * @param {String} seperator * @returns {Array} * @memberOf Array * @see Array * @since Standard ECMA-262 3rd. Edition * @since Level 2 Document Object Model Core Definition. * @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html */ Array.prototype.join = function(seperator){return [];};
<html> <body> <script type="text/javascript"> var arr = new Array(3); arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" document.write(arr.join()); document.write("<br />"); document.write(arr.join(".")); </script> </body> </html>
George,John,Thomas George.John.Thomas
var newText = "<span>" + $("p").text().split(" ").join("</span> <span>") + "</span>";
<p>Test is a demo.</p>
<p><span>Test</span> <span>is</span> <span>a</span> <span>demo.</span></p>
var arr = [ "a", "b", "c", "d", "e" ] $("div").text(arr.join(", ")); arr = jQuery.map(arr, function(n, i){ return (n.toUpperCase() + i); }); $("p").text(arr.join(", ")); arr = jQuery.map(arr, function (a) { return a + a; }); $("span").text(arr.join(", "));
1./* 2.JScript does not default the separator to “,” if the separator value is undefined. 3.*/ 4. var array = [1, 2]; 5. alert(array.join()); 6. alert(array.join(undefined)); 7. alert(array.join('-')); 8./* 9.Output: 10. IE: 1,2 1undefined2 1-2 11. FF: 1,2 1,2 1-2 12. Opera: same as FF 13. Safari: same as FF 14.*/