3

在 Anki 中,我有一个笔记类型,其中一张卡片实际上是完形填空删除,但是我同时使用其他卡片,其中包含完形填空删除字段。我尝试使用 javascript 替换两个 '\' 内的所有内容,并且在编辑时它似乎可以在预览中工作,但是当卡片在正常使用过程中出现时,只有第一行显示为纯文本。我正在使用桌面 linux 程序进行编辑,但也希望能够在 AnkiDroid 中使用它。

所以问题是:问题是什么,我该如何解决?

正面模板:

<script>
    function showDef() {
        document.getElementById("def").innerHTML = '{{Bedeutung 1}}'.replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
    };

    var initial = false;
    var beispiel = (function () {/*{{Beispiel 1}}*/}).toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
    var splitBeispiel = beispiel.split('\\');
    document.write(splitBeispiel[0] + "<n id='cloze'>[...]</n>" + splitBeispiel[2]);
</script>
<p onclick="showDef()" id="def">Click to show definition</p>

造型:

.card {
 font-family: arial;
 font-size: 20px;
 text-align: center;
 color: black;
 background-color: white;
}

#cloze {
 font-family: arial;
 font-size: 25px;
 text-align: center;
 color: blue;
 background-color: white;
}

#def {
 font-family: arial;
 font-size: 15px;
 text-align: center;
 color: green;
 background-color: white;
}

#beispiel {
 font-family: arial;
 font-size: 15px;
 text-align: center;
 color: orange;
 background-color: white;
}

返回模板:

<script>
var initial = false;
var beispiel = (function () {/*{{Beispiel 1}}*/}).toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, '');
var splitBeispiel = beispiel.split('\\');
document.write(splitBeispiel[0] + "<n id='cloze'>" + splitBeispiel[1] +"</n>" + splitBeispiel[2]);
</script>

<hr id=answer>

{{Singular Nominativ}}

以下示例中的“Beispiel 1”字段为“ein kirchlicher, ein \gesetzlicher\ Feiertag”

编辑器预览截图: 编辑器预览截图

测试截图: 测试截图

4

1 回答 1

-1

我想,你应该在这里寻找解决方案。例如,避免document.write在模板中使用并使用document.getElementById("HTMLidToReplace").innerHTML = '<b>' + your_var + '</b>';. 希望能帮助到你。

于 2018-02-17T13:29:13.183 回答