0
我想做一個文本解析器的種類,我做了大量的研究。JS文本解析器不工作
我想知道如果我正確使用JavaScript。我知道你不應該在js中創建文本解析器,但它是我知道的唯一腳本語言。
這裏是我到目前爲止的代碼:
<script>
function makeCode() {
for (i = 0; i < userCode.length; i++) {
if (userCode.substring("print:"(0, 6)) {
document.write(usercode.substring("print:"(6,0));
}
</script>
<style>
p {
text-align: center;
color: #cc0000;
}
h1 {
text-align: center;
font-family: Impact;
color: #cc0000;
}
body {
text-align: center;
}
form {
text-align: center;
}
</style>
<h1>NCPL</h1>
<p style="font-size: 10px">In Browser NinjaCorp Programming Language Editor</p>
</head>
<body>
<form name="userCode">
<textarea id="userCode" name="userCode" cols="80" rows="20" placeholder="Type your code here"></textarea></br>
<a href="javascript:makeCode()"><button type="button">Run Code!</button></a>
</form>
什麼問題了嗎? – theonlygusti
不使用document.write()它可以是一種評估形式。 – jmingov
''userCode''在你的函數中是未定義的。你必須首先從DOM中獲取它,類似於'var userCode = document.getElementById('userCode').value''。此外,你使用子串是沒有意義的。那裏的固定字符串「打印」是什麼?當用戶點擊按鈕時應該發生什麼? – Antares42