我使用方括号作为我的文本编辑器。我已经用过很多次了,但这是我第一次遇到这个问题。当我写代码时,我没有得到错误,但当我运行它时,它不工作。我试着调试它,并在chrome中打开了调试工具。但是,当我单击console时,它显示为空。下面列出了我的代码。
HTML代码:
<html>
<head>
<script type="text/javascript" src="myscript.js"></script>
</head>
<body>
<div class="calc" id="calculator">
<input type="text" name="#1" id="number1" enter code here"
placeholder="Enter Text" >
<input type="button" name="tryme" id="tryme" value="Try Me" onclick="tryme();">
<p id="answer" ></p>
</div>
</body>
</html>JavaScript代码:
/*eslint-env browser*/
function tryme() {
var str = document.getElementById("tryme");
var res = str.slice(0,2);
alert("aaa");
if (res==("Py")) {
document.write = str;
}
else{
document.write = "Py" + str;
}
}发布于 2018-05-02 00:25:34
你想要document.write( str )而不是document.write = str。这就是用str覆盖document.write函数。
https://stackoverflow.com/questions/50120099
复制相似问题