输入框中的文字,并清空输入框。(留言板)。div能够拖动。
注意:事件和哪个节点绑定。以及添加事件和移除事件的对象。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="text" id="textId" />
<input type="button" id="buttonId" value="执行" />
<div id="divId" style="width: 300px;height: 300px;border: 1px red solid; position: absolute;">
</div>
</body>
<script type="text/javascript">
var text = document.getElementById("textId");
var btn = document.getElementById("buto");
var div = document.getElementById("divId");
var textCont = "";
btn.οnclick= function(){
textCont = text.value +textCont;
div.innerText = textCont;
text.value = "";
}
div.addEventListener("mousedown",fun ,false);
function fun(){
document.onmousemove = function(event){
div.style.top = event.clientY+"px";
div.style.left = event.clientX+"px";
console.log(event.clientX +" "+ event.clientY);
}
}
document.onmouseup = function (){
document.onmousemove = null;
}
</script>
</html>