所以。这是我正在使用的javascript解析器的起始代码。这是什么问题:在让let进入的任何时间它都会崩溃。因此,如果我尝试键入,它将冻结页面,因此我必须重新加载。该效果仅在我开始键入后发生,因为它是一个onchange
事件。有人可以帮我吗?感谢所有帮助!
document.write('not working');
let jsAreas = document.getElementsByClassName('jsArea')
document.write('Not working')
String.prototype.splice = function(idx, rem, str) {
return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem));
};
let commenter = document.getElementById('commenter')
for(let i = 0; i < jsAreas.length; i++){
let jsArea = jsAreas[i]
jsArea.addEventListener('keyup', e => {
commenter.textContent = ''
let varRegex = /let/g
var b = document.getElementsByTagName('b');
while(b.length) {
var parent = b[ 0 ].parentNode;
while( b[ 0 ].firstChild ) {
parent.insertBefore( b[ 0 ].firstChild, b[ 0 ] );
}
parent.removeChild( b[ 0 ] );
}
while(varRegex.test(jsArea.innerHTML)){
commenter.textContent += varRegex.lastIndex
jsArea.innerHTML = jsArea.innerHTML.splice(varRegex.lastIndex - 3, 0, '<b>')
jsArea.innerHTML = jsArea.innerHTML.splice(varRegex.lastIndex + 3, 0, '</b>')
}
commenter.textContent += `Comment: This is the found: ${jsArea.innerHTML.match(varRegex)}. This is the other thing: ${jsArea.innerHTML}. The last index is: ${varRegex.lastIndex} `
})
}
<!-- This is a static file -->
<!-- served from your routes in server.js -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Glitch!</title>
<meta name="description" content="A cool thing made with Glitch">
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
<!-- import the webpage's client-side javascript file -->
<script src="/client.js" defer></script>
</head>
<body>
<div class="jsArea" contenteditable="true">let=</div>
<p id='commenter'>
Comments:
</p>
<footer>
Made with <a href="https://glitch.com">Glitch</a>!
</footer>
<!-- include the Glitch button to show what the webpage is about and
to make it easier for folks to view source and remix -->
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
<script src="https://button.glitch.me/button.js"></script>
<script src="https://rare-leek.glitch.me/client.js">
</script>
</body>
</html>