Created
June 12, 2018 01:20
-
-
Save QGB/258b59eb159130a421555008eaf92eb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Description | |
The sub() method embeds a string in a <sub> tag: "<sub>str</sub>". | |
Examples | |
Using sub() and sup() methods | |
The following example uses the sub() and sup() methods to format a string: | |
var superText = 'superscript'; | |
var subText = 'subscript'; | |
console.log('This is what a ' + superText.sup() + ' looks like.'); | |
// This is what a <sup>superscript</sup> looks like | |
console.log('This is what a ' + subText.sub() + ' looks like.'); | |
// This is what a <sub>subscript</sub> looks like. | |
///////////////////////////////////////////////////////////////// | |
stringvar.substr(start [, length ]) | |
返回一个从指定位置开始的指定长度的子字符串。如果 length 为 0 或负数,将返回一个空字符串。如果没有指定该参数,则子字符串将延续到 stringvar 的最后。 | |
/////////////////////////////////////////////////////////////// | |
strVariable.substring(start, end) | |
"String Literal".substring(start, end) | |
返回位于 String 对象中指定位置的子字符串。 | |
start | |
指明子字符串的起始位置,该索引从 0 开始起算。 | |
end | |
指明子字符串的结束位置,该索引从 0 开始起算。 | |
说明 | |
substring 方法将返回一个包含从 start 到最后(不包含 end )的子字符串的字符串。 | |
substring 方法使用 start 和 end 两者中的较小值作为子字符串的起始点。例如, strvar.substring(0, 3) 和 strvar.substring(3, 0) 将返回相同的子字符串。 | |
如果 start 或 end 为 NaN 或者负数,那么将其替换为0。 | |
子字符串的长度等于 start 和 end 之差的绝对值。例如,在 strvar.substring(0, 3) 和 strvar.substring(3, 0) 返回的子字符串的的长度是 3。 | |
示例 | |
下面的示例演示了 substring 方法的用法。 | |
function SubstringDemo(){ | |
var ss; // 声明变量。 | |
var s = "The rain in Spain falls mainly in the plain.."; | |
ss = s.substring(12, 17); // 取子字符串。 | |
return(ss); // 返回子字符串。 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chinaz get oversea address-ip