Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有定位标记和隐藏Div的jQuery选择器问题_Javascript_Jquery_Html - Fatal编程技术网

Javascript 带有定位标记和隐藏Div的jQuery选择器问题

Javascript 带有定位标记和隐藏Div的jQuery选择器问题,javascript,jquery,html,Javascript,Jquery,Html,我正在使用jquery。我有一个在xslt中动态生成的锚标记。每个锚点必须打开一个隐藏的div,并在onclick事件中传递不同的值 在隐藏分区中,我有两个不同的按钮,一个用于取消操作,另一个用于确认。这个想法是:当我点击确认按钮时,previus锚(在显示隐藏的div之前被点击)会得到其他样式(我使用addClass,工作正常)。我在单击函数上传递值$(this)以创建引用,它运行良好 问题是:当我在不同的锚点中单击(以显示div)时,上一个锚点被单击以获取新值。例如,如果我点击“a”按钮,显

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

在隐藏分区中,我有两个不同的按钮,一个用于取消操作,另一个用于确认。这个想法是:当我点击确认按钮时,previus锚(在显示隐藏的div之前被点击)会得到其他样式(我使用addClass,工作正常)。我在单击函数上传递值$(this)以创建引用,它运行良好

问题是:当我在不同的锚点中单击(以显示div)时,上一个锚点被单击以获取新值。例如,如果我点击“a”按钮,显示div,点击cancel(没有什么好的事情发生),然后我点击“b”按钮,点击confirm,“a”和“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)
传递给函数,但出于任何原因,它具有所有previus单击锚点的值。

我在JSFIDLE上创建了此函数的模拟版本:


它简化了很多,而且似乎工作正常。

Thx,工作正常,但不是我所希望的。。我的意思是,我不能向锚添加ID,因为它们是在没有ID的情况下自动生成的,我有很多ID在单击时运行相同的功能,问题是我有很多锚,指针(
$(this)
)超出了范围(我猜)还有一些问题……它们是由JavaScript还是服务器端脚本语言生成的?ID应该是无关的;正如您在脚本中看到的,它们只是用于测试以确保
$(此)
处于正确的上下文中。如果使用
警报(thisid.attr('id');
取消对函数第一行的注释,您将看到它引用了正确的对象(在本例中是DOM元素)。