我想制作各种文本解析器,我已经做了很多研究。
我想知道我是否正确使用了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>
答案 0 :(得分:0)
这是您要找的吗?
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>