How can i erase my data from textarea using javascript ?
This code:
<textarea class="m开发者_如何学编程ails" tabindex="1" onfocus="this.className='writing'" onblur="this.className='mails'" onkeypress="this.className='writing'" >يمكنك إضافة أكثر من بريد إلكتروني. أضف "," بين كل إدخال</textarea>
give your textarea an id first
<textarea id="txtarea" class="mails" tabindex="1" onfocus="this.className='writing'" onblur="this.className='mails'" onkeypress="this.className='writing'" >يمكنك إضافة أكثر من بريد إلكتروني. أضف "," بين كل إدخال</textarea>
and use this in your JS
document.getElementById("txtarea").value = "";
Try giving the textarea an ID
<textarea id="edit-text" class="mails" tabindex="1" onfocus="this.className='writing'" onblur="this.className='mails'" onkeypress="this.className='writing'" >aldkasdklad al;kd al;kd la;ksd al;kd l;aksl;dkal;skdl aksdl </textarea>
document.getElementById("edit-text").value = '';
the correct way of doing this is by setting the value property to an empty string.
Even if you don't set any property, the browser attaches all the specific properties to an element wen it's added to the dom.
However, if you are sceptic about the ".value" prop , you could try to alter the innerHTML of the element :
document.getElementById("edit-text").innerHTML = '';
精彩评论