2013-02-05 15 views
2

我不知道我的代码是否工作,因为我无法通过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> 
+0

是你错了粘贴HTML代码? – pktangyue

+1

你是如何看到这个错误的? –

+0

其在ln 2上的错误来自于crome控制台“Uncaught TypeError:无法设置属性'onclick'null” –

回答

3

ID名称是区分大小写的。您的onclick分配呼叫

document.getElementById("Paste").onclick = 

变化paste更改为Paste

而且它不是=+正确的一项+=

+0

得到Null消失。谢谢。但我的代码不会将文本框中的内容写入p标签。有任何想法吗? –

+0

根据你的意图,我认为你的最后一行应该是getInfo.innterHTML = paragraph; ..我得到了一个运行时错误ie ie检查这个为http://stackoverflow.com/questions/7892102/fixing-unknown-runtime-错误功能于IE8。 – 999k

1

你的选择是寻找一个id paste,但你的元素有一个ID Paste

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

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