2011-04-29 11 views

回答

2

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

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

不知道什么文本属性正在寻找,但我不得不做类似的事情,所以任何人都期待...

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

开始与你的页面上按钮:

<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都会切换(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 

注:

使用2011年第二季度Telerik的控制

使用外部JS文件

Refe分配办法:

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

例子用于获取触发信息是有点难以找到,但这里是一个: http://demos.telerik.com/aspnet-ajax/button/examples/clientsideevents/defaultcs.aspx

相关问题