我不知道我的代码是否工作,因为我无法通过onlclick是空的。我正在尝试从textarea中获取文本并将其放入HTML中的段落中。带有复选框。如果该框被选中,则将清除<p>
标记。如果未选中,它会将这些东西留在p标签中,然后制作一个新的p标签。谢谢你们onclick是空的?
window.onload = function() {
document.getElementById("paste").onclick = function() {
//var y = document.getElementById('paste').onclick
var paragraph = document.getElementById('box').value;
var x = document.getElementById("write");
var getInfo = document.getElementById('ParaWrite');
if (x.checked === true)
paragraph =+ "<p>"+paragraph+"</P>";
else
return;
getInfo.innterHTML === paragraph;
}
}
HTML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TeXt BoX</title>
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="Textbox.css">
</head>
<body>
<h1></h1>
<form name="form1" id="form1">
<input type='checkbox' name='write' id='write' value='Check' />
<label for='write'>Append Paragraph</label><br/>
<textarea type="text" id="box"/></textarea>
<input type='button' value="Paste typed text" id="Paste"/>
</form>
<p id="ParaWrite"></p>
<script type="text/javascript" src="TextPara.js"></script>
</body>
</html>
是你错了粘贴HTML代码? – pktangyue
你是如何看到这个错误的? –
其在ln 2上的错误来自于crome控制台“Uncaught TypeError:无法设置属性'onclick'null” –