我想运行函数来阻止表格的每一行。我想在加载 HTML 代码后这样做,我试试这个
<body>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/pyodide/dev/full/pyodide.js"
></script>
<script type="text/javascript">
async function main(kw) {
let pyodide = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/pyodide/dev/full/",
});
pyodide.globals.set("mikw", kw);
await pyodide.loadPackage("micropip");
await pyodide.runPythonAsync(`
import micropip
import js
await micropip.install('snowballstemmer')
import snowballstemmer
stemmer = snowballstemmer.stemmer('english')
div = js.document.createElement("div")
div.innerHTML = stemmer.stemWords('Hello this my default text '.split())
js.document.body.prepend(div)
varP = js.document.getElementById('origen').textContent
print(varP)
salida = stemmer.stemWords(varP.split())
print(salida)
divSalida = js.document.createElement("div")
div.innerHTML =salida
salida = stemmer.stemWords(mikw.split())
print(salida)
`);
}
main('This are the second text, I put this text on arguments function');
</script>
<div id="origen" >This text is inside of HTML element</div>
</body>
输出是
['This', 'text', 'is', 'insid', 'of', 'HTML', 'element']
['This', 'are', 'the', 'second', 'text,', 'I', 'put', 'this', 'text', 'on', 'argument', 'function']
但是我不能(或者我不知道)在加载 html 之后使用函数来阻止其他 kws,例如在加载 DOM 之后(获取我的 HTML 表的值并运行每个)
....
<div id="origen" onclick="temp()">This text is inside of HTML element</div>
<script>
myNewkwStemm=main('other word');
myNewkwStemm2=main('word2');
</script>
</body>