bug of 'clear text form' script

bug of 'clear text form' script

本文关键字:form script text clear bug of      更新时间:2023-09-26

我使用小脚本来清除文本形式的内容。它看起来很整洁,但是有一个bug。

如果我开始写,只是在表单的某个地方点击所有的内容被删除。

有什么办法解决这个问题吗??

要查看实际操作,请访问:

http://www.sandrophoto.com/2011/11/28/five-photography-tips-from-celebrated-pros/评论

开始写东西,而不是只是点击内部表单。看到了吗?文本被删除,这不是我需要的行为。

代码:

<textarea tabindex="4" rows="10" cols="100%" id="comment" name="comment"
    onclick="this.value='';" onfocus="this.select()"
    onblur="this.value=!this.value?'Write your comment':this.value;">
    Write your comment</textarea>

是否有办法使这个明确的文本行动只发生一次默认文本?然后保持静止?

如果要清除包含默认文本的this.value,则将其设为条件。

我很抱歉我不能提供一个代码示例。我对html没有足够的信心,以确保我没有误导你。

在textarea中有三种情况:

  1. onclick:清除文本区域
  2. onfocus:选择此文本区域
  3. onblur:如果为空白,则用Write your comment
  4. 代替

需要编辑的是action 1。(onclick)因为无论当前值是什么,每次用户单击时它都会清除它。仅当内容为默认设置(例如:Write your comment)时需要清除。

  1. 应该是:onclick:如果值是Write your Comment则清除,否则什么都不做。
所以你的代码应该是这样的:
<textarea tabindex="4" rows="10" cols="100%" id="comment" name="comment"
  onclick="if (this.value=='Write your comment'){this.value='';}" 
  onfocus="this.select()"
  onblur="this.value=!this.value?'Write your comment':this.value;">
  Write your comment</textarea>