Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 在变量中动态返回条件_Javascript_Jquery - Fatal编程技术网

Javascript 在变量中动态返回条件

Javascript 在变量中动态返回条件,javascript,jquery,Javascript,Jquery,基于给定条件操纵以下表达式的最佳方法是什么?例如 rtnData = ( $(this).find('span').text().match(regEx[1]) && $(this).find('span').text().match(regEx[2]) && $(this).find('span').text().match(regEx[3]) ); 正则表达式2或3在每种情况下都可能可用,也可能不可用 应该是这样的。即使在正则表达式数组中没有特

基于给定条件操纵以下表达式的最佳方法是什么?例如

rtnData = (
  $(this).find('span').text().match(regEx[1]) &&
  $(this).find('span').text().match(regEx[2]) &&
  $(this).find('span').text().match(regEx[3]) 
);

正则表达式2或3在每种情况下都可能可用,也可能不可用

应该是这样的。即使在正则表达式数组中没有特定项,这也不会产生影响

var rtnData = true;
var component = $(this);
regEx.forEach(function(currentRegEx) {
  rtnData = rtnData && component.find('span').text().match(currentRegEx)
});

应该是这样的。即使在正则表达式数组中没有特定项,这也不会产生影响

var rtnData = true;
var component = $(this);
regEx.forEach(function(currentRegEx) {
  rtnData = rtnData && component.find('span').text().match(currentRegEx)
});

我似乎无法让它为我工作。下面的一个运行良好,但我希望能够有4,5,6等在未来。另外,不确定“结果”是什么。对不起,最后一刻变量发生了变化。现在应该没事了,很好用。谢谢。我好像没办法让它为我工作。下面的一个运行良好,但我希望能够有4,5,6等在未来。另外,不确定“结果”是什么。对不起,最后一刻变量发生了变化。现在应该没事了,很好用。谢谢