0

我知道 jqMath 不支持一般较低的数学,因此我创建了一个使用 css 和 jQuery 的小工作,它在表格单元格的底部添加了一个边框。这在使用 fmath(假数学)来表示 MathML 表的 Chrome、IE 和 Safari 中运行良好,但是在使用本机 MathML 标记的 Firefox 中,它不受支持。事实上,我似乎根本无法使用 jQuery 向元素添加类,尽管我发现它们很好。话虽如此,是否有一个设置可以让我强制 Firefox(或其他浏览器)使用伪造的数学表,直到浏览器更好地支持它?或者,有没有一种我不知道的方法可以让我将 sum 行添加到本机 MathML 源?

一些思考代码:

<div class=”row math”&gt;
<div class=”col2”&gt;
<p><strong>First Equation</strong></p>
$\\table
x + y,=,9;
\cl "red"{6}+ y,=,9;
6 + y,=,9;
\cl "math-sum red redunderline" {-6},\cl "math-sum redunderline" {&nbsp;}, \cl "math-sum red redunderline" {-6};
y,=,\cl "red" {3};$ <br/>
<p> The solution to this system is <br />
  x = 6, y = 3.</p>
</div>
<div class=”col2”&gt; $\table
x - y,=,3;
\cl "red" {6}- y,=,3;
6 + y,=,9;
\cl "redunderline math-sum red"{-6},,\cl "redunderline math-sum red"{-6};
-y,=,\cl "red" {-3};
y,=,\cl "red" {3};$ <br>
<p> The solution to this system is <br />
  x = 6, y = 3.</p>
</div>
</div>

处理下划线的 CSS

<style type=”text/css”&gt;
/* jqMath is using important tags which requires important to override contents inside a css file*/
.math .math-sum.red,
.redunderline { 
    border-bottom: #a20000 1px solid !important; 
}
</style>

jQuery移动下划线:

// Add red underline to jqMath fake table markup
if($('td.fm-mtd:has(.red.math-sum)').selector === 'td.fm-mtd:has(.red.math-sum)') {
    $('td.fm-mtd:has(.red.math-sum)').addClass('redunderline');
}
if($('td.fm-mtd:has(.red.math-sum-row)').selector === 'td.fm-mtd:has(.red.math-sum-row)') {
    $('td.fm-mtd:has(.red.math-sum-row)').parent().addClass('redunderline');
}

if($('td.fm-mtd.mrow:has(.red.math-sum-row)').selector === 'td.fm-mtd.mrow:has(.red.math-sum-row)') {
    $('td.fm-mtd:has(.red.math-sum-row)').parent().addClass('redunderline');
}


// Add red underline for real math table markup
if($('mtd:has(.red.math-sum))').selector === 'mtd:has(.red.math-sum)') {
    $('mtd:has(.red.math-sum)').addClass('redunderline');
    //addClassML($('mtd:has(.red.math-sum)'),'redunderline');
}

// This SHOULD work, but doesn't add the class in FF
//$('.red.math-sum').parent().parent().addClass('redunderline'); 
if($('mtd:has(.red.math-sum-row))') != " ") {
    addClassML($('mtd:has(.red.math-sum-row)').parent(),'redunderline');
}
if($('mtd:has(.red.math-sum))') != " ") {
    addClassML($('mtd:has(.red.math-sum)').parent(),'redunderline');
}


/* This is NOT the prefered way to add a class - Firefox was ignoring addClass jQuery
function when in math markup */

function addClassML(element,newClassString){
if(typeof element === 'object' && newClassString === 'string' && newClassString.length > 0) {
    var i,n=0;
    newClass=newClassString.split(",");
    for(i=0;i<newClass.length;i++){
        var currentClass = $(element).attr("class");
        if(typeof(currentClass) == 'string' && currentClass > 0) {
           if(currentClass.indexOf(" "+newClass[i]+" ")==-1){
                   $(element).attr("class",currentClass+=" "+newClass[i]);
                   n++;
           }
        } else {
            $(element).attr("class",newClass[i]);
        }
    }
    return n;
} else {
    return -1;
}
} 
4

1 回答 1

0

我在使用 jQuery 向 XML 元素(例如 Firefox MathML 元素)添加类时也遇到了麻烦。请参阅M.addClassjqmath-0.4.0.js 以了解我在 jqMath 中所做的事情 - 基本上我调用element.setAttribute('class', ...)XML 元素,这相当于您的addClassML. (或者也许 jQuery 的更高版本.addClass()可能会在某一天自己做到这一点?)

正如您所说, jqMath 或 Firefox MathML 不支持MathML 的初等数学 ( http://www.w3.org/TR/MathML3/chapter3.html#presm.elementary )。但它只处理数字和操作,而不是变量,无论如何都不会严格涵盖您的示例。

于 2013-05-15T16:33:38.000 回答