简体   繁体   English

剑道UI电网单选按钮更改事件不触发?

[英]Kendo UI grid radio button changed event not firing?

I have a Kendo grid which shows a questionnaire. 我有一个显示调查表的剑道网格。 The question id and question is fetched from the database using AJAX call. 问题ID和问题是使用AJAX调用从数据库中获取的。 I am adding the radio buttons to the grid at run-time. 我在运行时将单选按钮添加到网格中。

My problem is that the radio buttons are not firing the changed event. 我的问题是单选按钮未触发更改的事件。 My code is below: 我的代码如下:

    <div style="height: 950px;" id="grdQuestions"></div>        

            <div style="text-align: center; margin-top: 10px;">
                <button class="k-button" id="submitresults" type="submit">Submit Results</button>
            </div>

 <script>
                $(document).ready(function () {

                    var dataSource = new kendo.data.DataSource({
                        transport: {
                            read: {
                                type: "GET",
                                url: "/AjaxHandler.aspx?requesttype=getquestions",
                                dataType: "json",
                                contentType: "application/json; chartset=utf-8"
                            }
                        },
                        pageSize: 25
                    });

                    $("#grdQuestions").kendoGrid({
                        dataSource: dataSource,                          
                        pageable: {
                            pageSizes: true
                        },
                        columns: [
                        {
                            field: "QuestionsId",
                            title: "Question Id",
                            width:90
                        },
                        {
                            field: "QuestionText",
                            title: "Question",
                            width:700
                        },
                        {
                            title: "Not me at all",
                            template: "<input class='radioq' type='radio' name=" + "'" + "select" + '#: QuestionsId #' + "'" + "id=" + "'" + "notme" + '#: QuestionsId #' + "'" + "/>",
                        },
                        {
                            title: "This is true some of the time",
                            template: "<input class='radioq' type='radio' name=" + "'" + "select" + '#: QuestionsId #' + "'" + "id=" + "'" + "strue" + '#: QuestionsId #' + "'" + "/>"
                        },
                        {
                            title: "This is true most of the time",
                            template: "<input class='radioq' type='radio' name=" + "'" + "select" + '#: QuestionsId #' + "'" + "id=" + "'" + "mtrue" + '#: QuestionsId #' + "'" + "/>"
                        },
                        {
                            title: "This is me",
                            template: "<input class='radioq' type='radio' name=" + "'" + "select" + '#: QuestionsId #' + "'" + "id=" + "'" + "itsme" + '#: QuestionsId #' + "'" + "/>"
                        }]
                    });

                    $("input[type='radio']").on("change", function () {                            
                        alert(this.value);
                    });
                }); 
            </script>

Use this : this is to bind event for dynamically generated elements. 使用this:这是为动态生成的元素绑定事件。

$(document).on("change","input[type='radio']", function () 
{                            
      alert(this.value);
});

you should use event delegation for that 您应该为此使用事件委托

 $(document).on("change","input[type='radio']", function () { 
    alert(this.value);
 });

Event delegation allows you to attach a single event listener, to a parent element, that will fire for all children matching a selector, whether those children exist now or are added in the future. 事件委托使您可以将单个事件侦听器附加到父元素,该元素将为与选择器匹配的所有子对象触发,无论这些子对象现在存在还是将来添加。

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

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