Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

javascript - 如何使用javascript清除文本框(How to clear a textbox using javascript)

I have a(我有一个)

<input type="text" value="A new value">

I need a javascript method to clear the value of the textbox when the focus is on the textbox.(当焦点在文本框上时,我需要一个javascript方法来清除文本框的值。)

How can this be achieved?(怎么能实现这一目标?)

  ask by kalls translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

just get element using(只是使用元素)

   function name()
   {  
   document.getElementById('elementid').value = "";
   }

you can call this function on onfocus event of textbox and clear the value(您可以在文本框的onfocus事件上调用此函数并清除该值)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...