我有一个带有元素 id 的 DIV;例如“bgjhkn2n2-20”。我正在尝试正确使用正则表达式,以便可以根据 id 将报告动态加载到 div 中。
console.log(elemID) 按预期打印 bgjhkn2n2-20 。它没有打印通常作为元素 ID 前缀的 #。console.log(repDBID[0])
打印完整的元素 ID;但我无法让萤火虫打印我从 regextester 中的类似测试中获得的组console.log(repDBID[0])
。如果我将索引号附加到 match 语句,它将返回 null。
帮助?
var baseURL = window.location.protocol + "//" + window.location.hostname + "/db/";
var genREP = "?a=API_GenResultsTable&qid=";
$('#tab1 div').each(function (e){
var elemID = this.getAttribute('id');
console.log(elemID);
var pattern=/([a-z0-9]{9})-([1-9]{1}[0-9]*)/g
var repDBID = elemID.match(pattern); //get dbid
console.log(repDBID[0]);
var repID = elemID.match(pattern)[2]; //get qid
//console.log(repID);
//$(this).load(baseURL+repDBID+genREP+repID);
$('#repTabs').tab(); //initialize tabs
});