开发者

how to delete contents from input box

I am a beginner with JavaScript.What开发者_开发问答 should i do to delete the contents from my input box.This is my code,

<html>
<head>
</head>
<body>
<p>Enter your name....</p>
<input id="myInput"/>
<button type="button" onclick="myFunction()">submit</button>
<div id="result"/>
<script type="text/javascript">
function myFunction(){
    var input=document.getElementById("myInput").value;
    document.getElementById("result").innerHTML='U sure '+input+' is your name';
    myInput="";
}
</script>
</body>
</html>


Coz you're a beginner with Javascript, I would recommend using Jquery. it would change your life-of-crossbrowser-issues to heaven (for future reference :) ).

Javascript :

document.getElementById("myInput").value = '';

Jquery :

$('#myInput').val('');


document.getElementById("myInput").value = "";


You should probably check out jQuery after you know the basics about javascript.


document.getElementById("myInput").value = "";

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜