2011-04-19 36 views
0

我在JavaScript兼容性方面存在一些问题。我使用下面的代码来清除文本框模糊数据,当点击该文本框。此代码在IE浏览器3.6 &工作正常,但在Firefox 4不支持。一些错误是有错误控制台,如clearTextFrom is not defined & clearTextTo is not define。请检查以下代码&建议我如何在FF4上运行此代码。Firefox 4.0中的JavaScript问题

function clearTextFrom() { 
    if(document.getElementById("size_from").value=="From Year") 
     document.getElementById("size_from").value=""; 
} 

function clearTextTo() { 
    if(document.getElementById("size_to").value=="To Year") 
     document.getElementById("size_to").value=""; 
} 

等待您的快速响应。

由于提前 TANU

编辑:

<div class="yearsearch"> 
<input type='text' style='width: 60px;' name='size_from' maxlength='4' size='17' id='size_from' onfocus='clearTextFrom();' onkeyup="validNumbers(document.getElementById('size_from')); sync();"/> 
<input type='text' style='width: 60px;' name='size_to' maxlength='4' size='17' id='size_to' onfocus='clearTextTo();' onkeyup="validNumbers(document.getElementById('size_to'));"/> 
</div> 

这是我用来调用这些函数的代码。

+0

请,使代码的代码来了解更多。 – 2011-04-19 07:45:47

+0

你可以发布你调用的代码吗?在你的函数之外被提出(这对我来说很好)。 – ZeissS 2011-04-19 07:47:38

+0

抱歉,你的意思是什么。我无法理解。 – Tanu 2011-04-19 07:47:54

回答

1

改成这样:

<script language="javascript"> 
    function clearTextFrom(item) { 
     if(item.value=="From Year") 
      item.value=""; 
    } 

    function clearTextTo(item) { 
     if(item.value=="To Year") 
      item.value=""; 
    } 
</script> 


<div class="yearsearch"> 
<input type='text' style='width: 60px;' name='size_from' maxlength='4' size='17' id='size_from' onfocus='clearTextFrom(this);' value="From Year"/> 
<input type='text' style='width: 60px;' name='size_to' maxlength='4' value="To Year" size='17' id='size_to' onfocus='clearTextTo(this);'/> 
</div> 
在此代码要发送的每个文本框的相关功能

。我测试,FF4.0

样品中为我工作:http://jsfiddle.net/fkP2P/

+0

尝试过,但不适用于FF4。 – Tanu 2011-04-19 08:00:25

+0

查看编辑帖子中的示例网址。 [示例](http://jsfiddle.net/fkP2P/)在FF 4.0中工作 – 2011-04-19 08:08:29

+0

是的,我检查。这是工作在Firefox 3.6,但不是4. – Tanu 2011-04-19 09:15:44