JS文本解析器不起作用

JS Text Parser Not Working

本文关键字:不起作用 文本 JS      更新时间:2023-09-26

我想做一个文本解析器,我做了很多研究。

想知道我是否正确使用了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>

这是你要找的吗?

function makeBode() {
    var userCode = document.getElementById('userCode').value;
    var myDiv = document.getElementById('myDiv');
  
     // alert(userCode)
    for (i = 0; i < userCode.length; i++) {
       myDiv.innerHTML =  myDiv.innerHTML  + userCode.substring((i,i+6)) +'<br>'; 
    }
}
p {
    text-align: center;
    color: #cc0000;
  }
  h1 {
    text-align: center;
    font-family: Impact;
    color: #cc0000;
  }
  body { 
    text-align: center;
  }
  form {
    text-align: center;
  }
<div id="myDiv"></div>
<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">Typing here so there is some text to work with </textarea></br>
    <a href="javascript:makeBode();"><button type="button">Run Code!</button></a>
  
</form>