开发者

how to delete contents from input box

开发者 https://www.devze.com 2023-02-21 14:29 出处:网络
I am a beginner with JavaScript.What开发者_开发问答 should i do to delete the contents from my input box.This is my code,

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

精彩评论

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