用于清除焦点上的textarea和removeChild的函数

时间:2014-02-21 11:52:57

标签: javascript html

我试图在用户点击后清除textarea,这是我目前的方法

小提琴:http://jsfiddle.net/3Nxg2/

<textarea type="text" id="address" 
          onfocus="if(this.value===this.defaultValue)this.value=''" onblur="if(this.value==='')this.value=this.defaultValue">Input Address Here</textarea>

但是,当用户点击textarea时,我希望发生另一个事件/函数,就是这个,

  function removeImage(){
  selected =  document.getElementById("country").value;
  display = false;
  document.getElementById("country").value = "";
  selected = null;    
  var MyContainer = document.getElementById("container");
  MyContainer.removeChild(MyContainer.childNodes[0])
  {

所以我尝试了这个,但是当用户点击textarea时,我怎么能让其他事件工作:

<textarea type="text" id="address" onfocus="removeImage()"
              onfocus="if(this.value===this.defaultValue)this.value=''" onblur="if(this.value==='')this.value=this.defaultValue">Input Address Here</textarea>

2 个答案:

答案 0 :(得分:1)

尝试:

<textarea type="text" id="address" onfocus="removeImage(); if(this.value===this.defaultValue)this.value=''" onblur="if(this.value==='')this.value=this.defaultValue">Input Address Here</textarea>

(组合两个onfocus属性,否则第二个属性将覆盖第一个属性)

答案 1 :(得分:0)

function onFocus(){
  document.getElementById("address").value = "";
  document.getElementById("res").value = "Results will be displayed here";
  document.getElementById("valid").value = "";
  document.getElementById("valid2").value = "";
  document.getElementById("cor").value = "Changes will be displayed here";
  document.getElementById("street_number").value = "";
  document.getElementById("route").value = "";
  document.getElementById("locality").value = "";
  document.getElementById("administrative_area_level_1").value = "";
  document.getElementById("country").value = "";
  document.getElementById("postal_code").value = "";

  selected =  document.getElementById("country").value;
  display = false;
  document.getElementById("country").value = "";
  selected = null;    
  var MyContainer = document.getElementById("container");
  MyContainer.removeChild(MyContainer.childNodes[0]);

  map.setCenter(defaultLatLng);
  map.setZoom(0);
  marker.setMap(null);

  }

<textarea type="text" id="address" onclick="onFocus()">Input Address Here
</textarea>

认为我可以做这样的事情,tnx为想法的人,发布它可能为其他有同样问题的人