Kendo UI网格单选按钮改变了事件没有解雇?

时间:2014-06-16 13:39:23

标签: jquery kendo-ui

我有一个显示调查问卷的Kendo网格。使用AJAX调用从数据库中获取问题ID和问题。我在运行时将单选按钮添加到网格中。

我的问题是单选按钮没有触发更改的事件。我的代码如下:

    <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>

2 个答案:

答案 0 :(得分:1)

使用:这是为动态生成的元素绑定事件。

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

答案 1 :(得分:1)

你应该使用event delegation

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

事件委托允许您将单个事件侦听器附加到父元素,该元素将为匹配选择器的所有子项触发,无论这些子项现在是存在还是将来添加。