【问题标题】:How to insert javascript code into Jupyter如何将 JavaScript 代码插入 Jupyter
【发布时间】:2016-12-27 19:35:42
【问题描述】:

我正在尝试将此脚本插入 custom.js。我将所有负数货币更改为红色。

我希望它适用于打印在 Jupyter 上的所有 pandas 数据帧。将它添加到 jupyter/anaconda 文件夹上所有可用的 custom.js 后,它仍然没有改变任何东西。有人可以帮我吗?

var allTableCells = document.getElementsByTagName("td");
for(var i = 0, max = allTableCells.length; i < max; i++) {
    var node = allTableCells[i];

    //get the text from the first child node - which should be a text node
    var currentText = node.childNodes[0].nodeValue; 

    //check for 'one' and assign this table cell's background color accordingly 
    if (currentText.includes("$ -"))
        node.style.color = "red";
}

【问题讨论】:

    标签: javascript python pandas anaconda jupyter


    【解决方案1】:

    use the jupyter javascript magic

    %%javascript
    var allTableCells = document.getElementsByTagName("td");
    for(var i = 0, max = allTableCells.length; i < max; i++) {
        var node = allTableCells[i];
    
        //get the text from the first child node - which should be a text node
        var currentText = node.childNodes[0].nodeValue; 
    
        //check for 'one' and assign this table cell's background color accordingly 
        if (currentText.includes("$ -"))
            node.style.color = "red";
    }
    

    【讨论】:

    • 谢谢!当我把它放在最后一个单元格上时,它就起作用了。每次我运行一个单元格时,jupyter 是否有可能加载这个脚本?
    猜你喜欢
    • 2022-01-10
    • 2016-07-05
    • 2016-10-21
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    相关资源
    最近更新 更多