jQuery选择器问题与锚标签和隐藏Div

jQuery Selector Issue With Anchor Tags and Hiding Div

本文关键字:隐藏 Div 标签 选择器 问题 jQuery      更新时间:2023-09-26

我正在使用jquery。我有一个在xslt中动态生成的锚标记。每个锚必须打开一个隐藏的div,并在onclick事件中传递不同的值。

在隐藏的div中,我有2个不同的按钮,一个用于取消操作,另一个用于确认。这个想法是:当我点击确认按钮前一个锚(点击之前显示隐藏的div)得到其他样式(我使用addClass,工作得很好)。我在click函数上传递值$(this)来创建引用,它工作得很好…

问题:当我点击不同的锚点(显示div)时,先前的锚点被点击获取新值。例如,如果我点击"a"按钮,显示div,点击"取消"(没有发生什么好事),然后我点击"b"按钮,点击"确认","a"answers"b"获得样式。

我只需要显示所选按钮的样式,但我不知道如何做到这一点。

我代码:

function showInfo(team, selectName, selectId, temps, thisid){
    //Create a function that will recieves some values            
 var showInfoLink = thisid; //Asigh a new variable the value of thisid ( $(this) )
 showInfoLink.removeClass("highlighted");
 //Show the component
 $("#com_advanceBet").css('z-index' , '1' );
//in the component is a select, it will show the name on the anchor of the selected item                
 $("select").change(function () {
   var str = "";
   $("select option:selected").each(function () {
   str += $(this).text() + " ";
   });
   showInfoLink.html(str);
 })
 .change();
//once i click here the anchor will have this class 
   $('#com_continueBet').click(function(){
   showInfoLink.removeClass('nostyle');
   showInfoLink.addClass('highlighted');
 //hide the component
  $("#com_advanceBet").css('z-index' , '-999999');
  });               
}

这是锚:

<a href="#" onclick="showInfo('{$team}', '{$selectName}', '{$selectId}', '{$temps}', $(this) ); " class="nostyle" ><xsl:value-of select="$pt" disable-output-escaping="yes"/><span class="test" style="font-size:0.65em"><xsl:value-of select="$odds" disable-output-escaping="yes"/></span></a>

在锚中,我将$(this)传递给函数,但由于某种原因,它具有所有先前单击的锚的值。

我在jsFiddle上创建了一个模拟版本:http://jsfiddle.net/dPZJc/6/