Description
Returns a substring beginning at a specified location and having a specified length.
Syntax
stringvar.substr(start [, length ]) 
The substr method syntax has these parts: Part Description 
stringvar Required. A string literal or String object from which the substring is extracted. 
start Required. The starting position of the desired substring. The index of the first character in the string is zero. 
length Optional. The number of characters to include in the returned substring. 
Res
If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of stringvar.
The following example illustrates the use of the substr method:
function SubstrDemo()
{
  var s, ss;
  var s = "The quick brown fox jumped over the lazy yellow dog.";
  ss = s.substr(16, 3);
  // Returns "fox"
  return(ss);
}

解决方案 »

  1.   

    srcID返回对象的ID
    其中substr是截取字符串的[在你的代码中没有看到什么效果]
      

  2.   

    substr Method
    Returns a substring beginning at a specified location and having a specified length.stringvar.substr(start [, length ]) Arguments
    stringvarRequired. A string literal or String object from which the substring is extracted.startRequired. The starting position of the desired substring. The index of the first character in the string is zero.lengthOptional. The number of characters to include in the returned substring.Res
    If length is zero or negative, an empty string is returned. If not specified, the substring continues to the end of stringvar.Example
    The following example illustrates the use of the substr method.function SubstrDemo(){
       var s, ss;                //Declare variables.
       var s = "The rain in Spain falls mainly in the plain.";
       ss = s.substr(12, 5);  //Get substring.
       return(ss);               // Returns "Spain".
    }具体说本例,得到srcElement.id的去掉最后一个字符的子串
      

  3.   

    来个中文的substr 方法
    返回一个从指定位置开始的指定长度的子字符串。stringvar.substr(start [, length ])参数
    stringvar必选项。要提取子字符串的字符串文字或 String 对象。start必选项。所需的子字符串的起始位置。字符串中的第一个字符的索引为 0。length可选项。在返回的子字符串中应包括的字符个数。说明
    如果 length 为 0 或负数,将返回一个空字符串。如果没有指定该参数,则子字符串将延续到 stringvar 的最后。示例
    下面的示例演示了substr 方法的用法。function SubstrDemo(){
       var s, ss;                // 声明变量。
       var s = "The rain in Spain falls mainly in the plain.";
       ss = s.substr(12, 5);  // 获取子字符串。
       return(ss);               // 返回 "Spain"。
    }