如何在客户端获取 RadButton Toggle State 的 Text 属性? [Telerik ASP.NET AJAX 控件]

发布于 2024-11-04 05:27:05 字数 115 浏览 0 评论 0原文

我想使用 jquery 或任何其他方式获取它的 Text 属性...

请帮助我...

I want to Get The Text Property Of this using jquery or any other way...

Please help me....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-11-11 05:27:05

不确定正在寻找什么文本属性,但我必须做类似的事情,所以对于其他人来说...

在按钮调用函数时获取信息

从页面上的按钮开始:

<telerik:RadButton ID="rbtn_State" runat="server"
OnClientClicked="ToggleStateChange" ButtonType="ToggleButton"
ToggleType="CustomToggle">
<ToggleStates>
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/play.png" Selected="true" />
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/pause.png"/>
</ToggleStates>
</telerik:RadButton>

请注意,当用户单击 radbutton 时,将调用 ToggleStateChange 函数(如果您像我一样使用外部 js 文件,请务必添加对您的页面的脚本引用。)

现在,对于该函数:

function ToggleStateChange(sender, args) {
  //Start by getting all of the information about the current state
  //of the button
    var currentState = sender.get_selectedToggleState();
  //Now, there are a number of functions you can call - Refer to link below      
    var currentImageUrl = currentState.get_imageUrl();  //gets image URL text
}

获取信息另一个元素调用函数

例如,考虑一个自动折叠所有 div 按钮和单个 div 的单独自动折叠/展开按钮。如果打开了所选的自动折叠,则所有 div 都会切换 (divs.toggle();),并且用于折叠或展开 div 的单个按钮需要从折叠切换状态更改为展开切换状态,因为 div 已经折叠。

在调用元素调用的函数中(在我的例子中,自动折叠所有按钮调用 AutoCollapseAllDivs 函数),添加:

 //Find the button that needs to change toggle states
 //**When using $() to find the button, the structure of the button's 
 //information is not the same as when the button is the sender.**
 //In this case, the toggle information is under _control.
 var button = $('#rbtn_collapse')[0].control;  // note the use of [0]
 //Now pick a get/set method to implement
 //For example, change the toggle state
 button.set_selectedToggleStateIndex(1); //easy way is to set the index

注释:

使用 Q2 2011 Telerik Controls

使用外部 js 文件

参考:

radbutton 的基本方法: http: //www.telerik.com/help/aspnet-ajax/button-client-side-basics.html

获取切换信息的示例有点难找到,但这里有一个:
http://demos.telerik.com/aspnet-ajax/button /examples/clientsideevents/defaultcs.aspx

Not sure what text property was being looked for, but I had to do something similar, so for anyone else looking...

Getting information when the button is invoking the function

Start with your button on your page:

<telerik:RadButton ID="rbtn_State" runat="server"
OnClientClicked="ToggleStateChange" ButtonType="ToggleButton"
ToggleType="CustomToggle">
<ToggleStates>
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/play.png" Selected="true" />
<telerik:RadButtonToggleState ImageUrl="~/Images/Icons/pause.png"/>
</ToggleStates>
</telerik:RadButton>

Notice that when the user clicks the radbutton, the ToggleStateChange function is called (be sure to add a script reference to your page if you are using an external js file like me.)

Now, for the function:

function ToggleStateChange(sender, args) {
  //Start by getting all of the information about the current state
  //of the button
    var currentState = sender.get_selectedToggleState();
  //Now, there are a number of functions you can call - Refer to link below      
    var currentImageUrl = currentState.get_imageUrl();  //gets image URL text
}

Getting the information when another element invokes a function

For example, think of an auto collapse all divs button and individual auto collapse/expand button for a single div. If the auto collapse selected was turned on, all divs would toggle (divs.toggle();) and the individual button to collapse or expand the div needed to change from the collapse toggle state to the expand toggle state since the divs are already collapsed.

In the function that is called by the invoking element(in my case the auto collapse all button calling the AutoCollapseAllDivs function), add:

 //Find the button that needs to change toggle states
 //**When using $() to find the button, the structure of the button's 
 //information is not the same as when the button is the sender.**
 //In this case, the toggle information is under _control.
 var button = $('#rbtn_collapse')[0].control;  // note the use of [0]
 //Now pick a get/set method to implement
 //For example, change the toggle state
 button.set_selectedToggleStateIndex(1); //easy way is to set the index

Notes:

Using Q2 2011 Telerik Controls

Using external js file

References:

The basic methods for the radbutton: http://www.telerik.com/help/aspnet-ajax/button-client-side-basics.html

Examples for getting toggle information are a little harder to find, but here is one:
http://demos.telerik.com/aspnet-ajax/button/examples/clientsideevents/defaultcs.aspx

呢古 2024-11-11 05:27:05

您应该获取当前选定的 ToggleState,然后从 ToggleState 中获取文本。
这是一个示例代码片段:

var button = $find("RadButton1");
var text = button.get_selectedToggleState().get_text();
alert(text);

You should get the currently selected ToggleState, and then get the text from the ToggleState.
Here is a sample code snippet:

var button = $find("RadButton1");
var text = button.get_selectedToggleState().get_text();
alert(text);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文