Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 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 Answer

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事件上调用此函数并清除该值)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...