2

我不知道我的代码是否有效,因为我无法通过 onlclick 为空。我正在尝试从 textarea 中获取文本并将其放入 HTML 的段落中。带有复选框。如果选中该框,则它将清除<p>标签。如果未选中,它将把这些东西留在 p-tag 中,然后制作一个新的 p-tag。多谢你们

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>
4

2 回答 2

3

id 名称区分大小写。将您的 onclick 分配调用更改为

document.getElementById("Paste").onclick = 

更改pastePaste

也不=+正确的一个是+=

于 2013-02-05T04:16:40.583 回答
1

您的选择器正在寻找一个 id paste,但您的元素有一个 id Paste

var thisWillBeNull = getElementById('paste') ==> null

thisWillBeNull.onclick ==> TypeError: Cannot read property 'onclick' of null

于 2013-02-05T04:15:17.647 回答