【问题标题】:jQMath - Elementary math Sum line equivalent in MathMLjQMath - MathML 中等效的初等数学总和线
【发布时间】:2013-05-14 20:22:05
【问题描述】:

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

一些思考代码:

<div class=”row math”>
<div class=”col2”>
<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”> $\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”>
/* 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;
}
} 

【问题讨论】:

  • 你有什么问题?

标签: jquery math mathml jqmath


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    • 2017-05-19
    相关资源
    最近更新 更多