简体   繁体   English

在VB Click事件中无法识别由javascript更改的类

[英]Class changed by javascript not recognised in VB click event

On my page I have two tabbed sections of content. 在我的页面上,我有两个选项卡式的内容部分。 When the page is first loaded, the first tabbed area is displayed and the other one is hidden. 首次加载页面时,将显示第一个选项卡式区域,而另一个则被隐藏。 I have some javascript in place which switches tabs and hides/displays the relevant content when one of the tabs are clicked. 我有一些javascript,当单击其中一个标签时,该标签可切换标签并隐藏/显示相关内容。 To mark which tab is the active tab, the active tab is given the class of "current". 为了标记哪个选项卡是活动选项卡,活动选项卡被赋予“当前”类别。

When I submit a button on that page, I want it to do one of two things depending on which tabbed area is displayed. 当我在该页面上提交按钮时,我希望它根据显示的选项卡区域执行以下两项操作之一。 To find out which tab has been clicked, I check the class attribute of each tab: 为了找出单击了哪个选项卡,我检查每个选项卡的class属性:

Select Case True
   Case tab1.Attributes("class").Contains("current")
   ....
   Case tab2.Attributes("class").Contains("current")
   ....
End Select

However, checking the class attribute in this way shows that even though tab2 has been selected, tab1 always has the "current" class. 但是,以这种方式检查class属性显示,即使已选择tab2,tab1始终具有“当前”类。

If however I create a hidden input like this: 但是,如果我创建这样的隐藏输入:

<input type="hidden" id="SelectedTab" runat="server" class="SelectedTab" />

and then whilst changing tabs in my javascript, also set the name of the selected tab to display in the value of the hidden input, the correct tab name is recognised from the click event in my VB code. 然后在我的javascript中更改标签时,还设置选定标签的名称以显示在隐藏输入的值中,则可以从我的VB代码中的click事件中识别出正确的标签名称。

Could someone please explain why this is? 有人可以解释为什么吗?

代替使用隐藏字段,而使用asp.net隐藏字段控件,然后再次尝试相同的操作。

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

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