如下题匹配选项:
(1) 设集合 $A=[-1,2], B=\left{y \mid y=x^{2}, x \in A\right}$, 则 $A\cap B=$
A. $[1,4]$
B. $[1,2]$
C. $[-1,0]$
D. $[0,2]$
直接上代码:
function getOption(str,from,to)
{
var r = 'var reg = /[\(]*'+from+'[:|:|、|.]{1}(.*?)[\s]?'+ to +'/';
// console.log(r);
eval(r);
var arr = str.match(reg);
console.log(arr);
return arr[1].replace('<br/>','').replace('</p><p style=\"white-space: normal;\">','');
//return str.match(reg)[1];
}
格式化数据:
function formatContent(content)
{
content = content.replace('\(A\)','A.').replace('\(B\)','B.').replace('\(C\)','C.').replace('\(D\)','D.').replace('\(E\)','E.').replace('\(F\)','F.');
content = content.replace('<br/>','');
content = content.replace('<br>','');
content = content.replace('</p><p>');
content = content.replace('<x','\\lt x');
return content;
}
设置选项:
function setChoiceItem()
{
var list =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q'];
var ue = UE.geEditor('question-content');
var content = formatContent(ue.getContent());
console.log(content);
var str = content;
//console.log(getOption(str,'A','B'));
//console.log(getOption(str,'B','C'));
//console.log(getOption(str,'C','D'));
//console.log(getOption(str,'D','$'));
//$('p.optionContent:eq(0)').html(getOption(content,'A','B'));
//$('p.optionContent:eq(1)').html(getOption(content,'B','C'));
//$('p.optionContent:eq(2)').html(getOption(content,'C','D'));
//$('p.optionContent:eq(3)').html(getOption(content,'D','$'));
var len = $('p.optionContent').length;
$('p.optionContent').each(function(index,e){
console.log(list[index]);console.log(len);
var start = list[index];
var end = list[index+1];
if(index == len-1)
{
end='$';
}
$(this).html(getOption(content,start,end));
});
}