【问题标题】:How to Get RadButton Toggle State's Text Property At Client Side ? [Telerik ASP.NET AJAX Controls]如何在客户端获取 RadButton 切换状态的文本属性? [Telerik ASP.NET AJAX 控件]
【发布时间】:2011-08-15 08:56:41
【问题描述】:

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

请帮帮我....

【问题讨论】:

    标签: jquery asp.net-ajax telerik


    【解决方案1】:

    你应该获取当前选中的ToggleState,然后从ToggleState中获取文本。 这是一个示例代码sn-p:

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

    【讨论】:

      【解决方案2】:

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

      按钮调用函数时获取信息

      从页面上的按钮开始:

      <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
      

      注意事项:

      使用 2011 年第二季度 Telerik 控件

      使用外部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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-20
        • 2012-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多