为什么html复选框功能只能在IE中工作,而不是在Firefox或Chrome? [英] Why html checkbox function only works in IE but not in Firefox or Chrome?

查看:129
本文介绍了为什么html复选框功能只能在IE中工作,而不是在Firefox或Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个JavaScript / JSP / Struts应用程序,它有一个复选框,对于高级搜索,当它被选中,其他2项应该显示在页面上,用户输入更多的信息,但这只是工作在IE中,但没有Firefox或Chrome,没有响应,当它在其他2个浏览器上检查,为什么?如何在所有浏览器中使用它?

I'm debugging a JavaScript/JSP/Struts app, it has a checkbox, for advanced search, when it's checked, other 2 items are supposed to show up on the page for user to enter more info, yet this only works in IE, but not Firefox or Chrome, no response at all when it's checked on the other 2 browsers, why ? And how to make it work in all browsers ?

<script type="text/javascript">
    function checkAdvSearch(checked) {      
        if(checked) {
            document.getElementById("searchTerm2").style.display = '';
            document.getElementById("searchField2").style.display = '';
        }else {
            document.getElementById("searchTerm2").style.display = 'none';
            document.getElementById("searchField2").style.display = 'none';
            document.getElementById("searchLOB").style.display = 'none';

            document.getElementById("searchTerm2").value = '';
            document.getElementById("searchField2").value = 'clientName';
            document.getElementById("searchStatus").value = '';
            document.getElementById("searchLOB").value = '';
        }
    }
</script>

...
<!-- for advanced search -->
  <td Valign=top width=300>
    <input type="checkbox" name="advSearch" onclick="checkAdvSearch(this.checked);" tabindex="5"/>Advanced Search
    <html:text property="searchTerm2" value="" style="display:none" tabindex="6"/>
  </td>
  <td Valign=top width=178>
    <html:select property="searchField2" onchange="showOptions2(this.form)" value= "" style="display:none" tabindex="7">
      <html:option value="clientName">Insured Name</html:option>
      <html:option value="policy">Policy Number</html:option>
        ...
    </html:select>
  </td>
...


推荐答案

发现了答案,在下面解决了这个问题,添加了styleId:

After some research I found the answer, added "styleId" to the following solved the problem :

<html:text property="searchTerm2" styleId="searchTerm2" value="" style="display:none" tabindex="6"/>

<html:select property="searchField2" styleId="searchField2" onchange="showOptions2(this.form)" value= "" style="display:none" tabindex="7">

styleId =xyz在处理后将变成Id =xyz document.getElementById(),否则会导致错误,因为它没有Id。

styleId="xyz" after processing will be turned into Id="xyz" which will be identified by document.getElementById(), otherwise it will cause error because there is no Id in it.

这篇关于为什么html复选框功能只能在IE中工作,而不是在Firefox或Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆