Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript/Jquery获取字符串的一部分_Javascript_Jquery_String - Fatal编程技术网

Javascript/Jquery获取字符串的一部分

Javascript/Jquery获取字符串的一部分,javascript,jquery,string,Javascript,Jquery,String,有可能得到第一个这样的字符串吗 loadTabContent('90', this, 'tabTabel', null); loadTabContent('101', this, 'tabTabel', null); 在第一个例子中,我希望一个变量返回'90',在最后一个例子中,我希望它返回'101'。我该怎么做?数字的长度是可变的,但总是从同一个位置开始。看起来不像字符串吗?无论如何,str.match(/\d+/)应该得到第一个数字!我发现我的字符串确实不正确。你知道我是否有一个oncli

有可能得到第一个这样的字符串吗

loadTabContent('90', this, 'tabTabel', null);
loadTabContent('101', this, 'tabTabel', null);

在第一个例子中,我希望一个变量返回'90',在最后一个例子中,我希望它返回'101'。我该怎么做?数字的长度是可变的,但总是从同一个位置开始。

看起来不像字符串吗?无论如何,
str.match(/\d+/)
应该得到第一个数字!我发现我的字符串确实不正确。你知道我是否有一个onclick属性,比如
onclick=“loadTabContent('90',this,'tabTabel',null);”
,如果我能把
loadTabContent('90',this,'tabtabtabel',null)放进去的话在字符串中?我尝试了
var tabString=$(“#”+tabID).attr(“onclick”),但javascript将所有内容都放在字符串中,而不仅仅是onclick属性的字符串值
<script type="text/javascript">
 var re = /'\d+(.*?)'/;
 var sourcestring = "source string to match with pattern";
 var results = [];
 var i = 0;
 for (var matches = re.exec(sourcestring); matches != null; matches = re.exec(sourcestring)) {
 results[i] = matches;
 for (var j=0; j<matches.length; j++) {
  alert("results["+i+"]["+j+"] = " + results[i][j]);
  }
 i++;
}
$matches Array:
  (
  [0] => Array
    (
        [0] => '90'
        [1] => '101'
    )

[1] => Array
    (
        [0] => 
        [1] => 
    )

 )