代码如下:<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>让iframe子窗体取父窗体地址栏参数(querystring)</title> <script type="text/javascript"> function f(){ //http://localhost:4101/MyFiles/netshop/ShopType.aspx?tid=1 var url = window.location.href;//取得地址栏 var pos = url.indexOf("tid");//简单做个字符串处理,这里只有一个参数。 var tid = url.substring(pos+4);//取tid=后面的字符串,所以+4...
split定义和用法 split() 方法用于把一个字符串分割成字符串数组。 语法 stringObject.split(separator, howmany)参数 描述 separator 必需。字符串或正则表达式,从该参数指定的地方分割 stringObject。 howmany 可选。该参数可指定返回的数组的最大长度。如果设置了该参数,返回的子串不会多于这个参数指定的数组。如果没有设置该参数,整个字符串都会被分割,不考虑它的长度。 返回值 一个字符串数组。该数组是通过在 separator...
代码如下://String对象的静态方法 Object.extend(String, { interpret: function(value) { return value == null ? : String(value); }, specialChar: { \b: \\b, \t: \\t, \n: \\n, \f: \\f, \r: \\r, \\: \\\\ } }); Object.extend(String.prototype, (function() { //内部方法,为gsub和sub函数初始化replacement参数 function prepareReplacement(replacement) { if (Object.isFunction(replacement)) return replacement; va...
substr函数和substring函数都是用来从某个“母字符串”中提取“子字符串”的函数。但用法有些差别,下面分别介绍substr 方法 定义和用法 substr 方法用于返回一个从指定位置开始的指定长度的子字符串。 语法 stringObject.substr(start [, length ]) 参数 描述 start 必需。所需的子字符串的起始位置。字符串中的第一个字符的索引为 0。 length 可选。在返回的子字符串中应包括的字符个数。 说明 如果start为负数,则start=str.len...
函数 :split() 功能 :使用一个指定的分隔符把一个字符串分割存储到数组 例子: str=”jpg|bmp|gif|ico|png”; arr=theString.split(”|”); //arr是一个包含字符值”jpg”、”bmp”、”gif”、”ico”和”png”的数组 函数 :John() 功能 :使用您选择的分隔符将一个数组合并为一个字符串 例子: var delimitedString=myArray.join(delimiter); var myList=new Array(”jpg”,”bmp”,”gif”,”ico”,”png”); var portableLis...
代码如下:String.prototype.HTMLEncode = function() { var temp = document.createElement ("div"); (temp.textContent != null) ? (temp.textContent = this) : (temp.innerText = this); var output = temp.innerHTML; temp = null; return output; } String.prototype.HTMLDecode = function() { var temp = document.createElement("div"); temp.innerHTML = this; var output = temp.innerText || temp.textContent; temp = ...
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。 语法 stringObject.indexOf(searchvalue,fromindex) 参数 描述 searchvalue 必需。规定需检索的字符串值。 fromindex 可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略该参数,则将从字符串的首字符开始检索。 说明 该方法将从头到尾地检索字符串 stringObject,看它是否含有子串 searchvalue。开始检索的位...
Split方法: 以下程序例子实现了split和整数字符串互转的用法。。。 <script > function evil() { var toint=parseInt("123");//字符串转换成整形 var intvalue=123; var tostr=intvalue.toString();//类型转换成字符串 var my_friends ="test1,test2,test3,test4,test5"; var friend_array =my_friends.split(","); for (loop=0; loop < friend_array.length;loop++) { document.writeln(friend_array[loop] + " is myfriend.<br>...
代码如下:// Initializes a new instance of the StringBuilder class // and appends the given value if supplied function StringBuilder(value) { this.strings = new Array(""); this.append(value); } // Appends the given value to the end of this instance. StringBuilder.prototype.append = function (value) { if (value) { this.strings.push(value); } } // Clears the string buffer StringBuilder.prototype.clea...
//获取字符数组 String.prototype.ToCharArray=function() { return this.split(""); } //获取N个相同的字符串 String.prototype.Repeat=function(num) { var tmpArr=[]; for(var i=0;i<num;i++) tmpArr.push(this); return tmpArr.join(""); } //逆序 String.prototype.Reverse=function() { return this.split("").reverse().join(""); } //测试是否是数字 String.prototype.IsNumeric=function() ...
Javascrīpt中字符串的方法: 1、改变字符串大小写 string.toUpperCase(); string.toLowerCase(); 2、字符串搜索 indexOf()方法用来确定一个短字符串是否在另一个长字符串中,若存在,则返回所在位置索引;若不存在,则返回值-1。 用法:长字符串.indexOf("短字符串") 3、提取字符副本和子字符串 charAt()方法可以从字符串指定位置提取单个字符。 substring()方法可用于提取一个连续的字符串,需提供起始和终止位置(注:终止...
大字符串的连接最好使用数组,把每个子串放入数组元素,再执行join()连接起来,其效率比+=有明显的提高。 因此,可以由此原理写一个简单的 StringBuffer 类,在遇到大字符串连接时可以派上用场。 //by misshjn function StringBuffer(){ this.data = []; } StringBuffer.prototype.append = function(){ this.data.push(arguments[0]); return this; } StringBuffer.prototype.toString = function(){ return this.d...
JavaScript中几乎每个对象都有一个 toString()方法,而且是内置的.用来输出当前 变量的信息. 但是对于我们最常用的Object对象.每次用 toString都是打印[object Object] {a:1,b:2,c:3}.toString() ===> [object Object] 让人十分郁闷,为此我实现了一个友好的,打印Object各成员的函数, 支持嵌套输出 ,也能友好打印数组内容. 这里贴出代码,希望和大家一起学习,一起完善,改进这个函数. 说句题外话,用 Vim写程序,可不是一般的爽啊. 我表...
toString 方法 返回对象的字符串表示。 objectname.toString([radix])参数 objectname 必选项。要得到字符串表示的对象。 radix 可选项。指定将数字值转换为字符串时的进制。 说明 toString 方法是所有内建的 JScript 对象的成员。它的操作依赖于对象的类型: 对象 操作 Array 将 Array 的元素转换为字符串。结果字符串由逗号分隔,且连接起来。 Boolean 如果 Boolean 值是 true,则返回 “true”。否则,返回 “false”。 ...
代码如下:/* Array */ Array.reverse() //数组反向排序,变成新数组。 Array.sort() //把数组按字符排序,变成新数组。 s=Array.push("str1","str2") //从后面添加数组,s为添加记录 s=Array.pop() //从后面删除数组,s为被删记录 s=Array.shift() //从前面删除数组,s为被删记录 s=Array.unshift("str1","str2") //从前面添加数组,s为添加记录 s=Arr...