【发布时间】:2011-11-12 11:26:50
【问题描述】:
我正在使用 jquery。我有一个在 xslt 中动态生成的锚标记。每个锚点都必须打开一个隐藏的 div 并在 onclick 事件中传递不同的值。
在隐藏的 div 中,我有 2 个不同的按钮,一个用于取消操作,另一个用于确认。这个想法是:当我单击确认按钮时,previus 锚(之前单击以显示隐藏的 div)获得其他样式(我使用 addClass,工作正常)。我在 click 函数上传递值 $(this) 来创建引用,它运行良好......
问题:当我点击不同的锚点(以显示 div)时,前一个被点击获取新值。例如,如果我单击“a”按钮,显示 div,单击取消(没有任何反应,那很好),然后单击“b”按钮并单击确认,“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) 传递给函数,但出于某种原因,它具有所有先前单击的锚点的值。
【问题讨论】:
标签: javascript jquery html