简体   繁体   English

jQuery函数只能在Internet Explorer中正常工作

[英]Jquery Function only half-works in Internet Explorer

I've gut a simple function in my page for hiding/showing panes when some tabs are clicked. 我在页面中保留了一个简单的功能,用于在单击某些选项卡时隐藏/显示窗格。 Simplest thing in the world, right? 世界上最简单的东西,对吧?

Works perfectly in Firefox and Chrome, but in IE it only half works. 在Firefox和Chrome中可以完美运行,但在IE中只有一半可以运行。 It will hide all the sopMonthContainers, but fails to find the container with a matching ID and display it. 它将隐藏所有的sopMonthContainers,但无法找到具有匹配ID的容器并显示它。

 $('.sopTab').click(function(e){
    if ($(this).hasClass("activeTab") === false){
        $(".sopTab").removeClass("activeTab");
        $(this).addClass("activeTab");
        };
    var selectionID = $(this).attr("id");
    $(".sopMonthContainer").css("display", "none");
    $(".sopMonthContainer#the"+selectionID).css("display", "block");
 });

I'm hoping it isn't some stupid typo that I've overlooked, but I've been staring at this thing for nearly an hour trying different variations on the theme. 我希望这不是我忽略的愚蠢错别字,但是我一直盯着这个东西近一个小时,尝试对主题进行不同的修改。 I've tried reworking the selector IDs to make sure they're unique (hence the "the" in the selector on the last line), I've tried selecting using only ID, I've tried using different methods to hide/show... same result no matter what. 我尝试重新处理选择器ID以确保它们唯一(因此,最后一行选择器中的“ the”),我尝试仅使用ID进行选择,尝试使用不同的方法来隐藏/显示...无论如何,相同的结果。

EDIT: the relevant markup. 编辑:相关的标记。 It's got some coldfusion elements, anything between ##'s is a coldfusion variable. 它具有一些ColdFusion元素,##之间的任何内容都是ColdFusion变量。

<div class="sopTab" id="sopContainer#DateFormat(pubdate,'mmmm')#" style="">
    #DateFormat(pubdate,"mmmm")#: <span id="sum#DateFormat(pubdate,"mmmm")#">0</span>
</div>

<cfoutput query="GetProductBasicInfo">
    <div class="sopMonthContainer" style="display:none;" 
    id="theSopContainer#DateFormat(pubdate,'mmmm')#">
        [div content goes here]
     </div>
</cfoutput>

Note for example this: 请注意以下示例:

<div class="sopTab" id="sopContainerNovember" style="">November: <span id="sumNovember">0</span></div>

<div class="sopMonthContainer" style="display:none;" id="theSopContainerNovember">

when you click on sopTab, the selector you build is 当您单击sopTab时,您构建的选择器是

#thesopContainerNovember
//  ^  

but the ID of the target is 但是目标的ID是

#theSopContainerNovember
//  ^

the IDs did not match(it's the uppercase and lowercase s ) ID不匹配(这是大写和小写s

I think that the last line should be 我认为最后一行应该是

$(".sopMonthContainer #the"+selectionID).css("display", "block");

There should be a space here. 这里应该有一个空格。 But I might be wrong. 但是我可能是错的。 It would help if you would post a link to a jsFiddle or working example. 如果您发布指向jsFiddle或工作示例的链接,将会有所帮助。

You have an error in your page. 您的页面有错误。 I noticed there's some code that looks like someone has attemped to comment it out but done it incorrectly. 我注意到有些代码看起来好像有人试图将其注释掉,但是做得不正确。

In your sopQuery.cfm file, change the code here: 在您的sopQuery.cfm文件中,在此处更改代码:

<script language="javascript">
<!--
  cfform_submit_status["productSelections"]=null;

  function check_TF_productSelections( theForm ){ 
    cfform_isvalid = true;
    cfform_error_message = "";
   cfform_invalid_fields = new Object();

    if ( cfform_isvalid ){
      return true;
    }else{
      alert( cfform_error_message );
      return false;
    }
  }

//-->
</script>

To this: 对此:

<!--
<script language="javascript">

  cfform_submit_status["productSelections"]=null;

  function check_TF_productSelections( theForm ){ 
    cfform_isvalid = true;
    cfform_error_message = "";
   cfform_invalid_fields = new Object();

    if ( cfform_isvalid ){
      return true;
    }else{
      alert( cfform_error_message );
      return false;
    }
  }


</script>
-->

OR... If the code is supposed to be uncommented, change it to this, but note that the error will persist as the variable cfform_submit_status is not defined anywhere: 或...如果应该取消注释该代码,请将其更改为该注释, 但请注意,该错误将继续存在,因为未在任何地方定义变量cfform_submit_status

<script language="javascript">

  cfform_submit_status["productSelections"]=null;

  function check_TF_productSelections( theForm ){ 
    cfform_isvalid = true;
    cfform_error_message = "";
   cfform_invalid_fields = new Object();

    if ( cfform_isvalid ){
      return true;
    }else{
      alert( cfform_error_message );
      return false;
    }
  }


</script>

Presumably it's supposed to be defined here: 大概应该在这里定义:

<script type="text/javascript" src="/bluedragon/scripts/cfform.js"></script>

But I looked and that file is empty. 但是我看了看,那个文件是空的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM