2014-06-16 83 views
0

我有一个显示问卷的Kendo网格。问题ID和问题是使用AJAX调用从数据库中提取的。我在运行时将单选按钮添加到网格中。Kendo UI网格单选按钮更改事件不发射?

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

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

回答

1

你应该使用event delegation

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

事件委派,您可以附加一个事件侦听器,以父元素,这将触发对所有选择匹配的孩子,那些孩子是否存在现在或将来添加。

+0

@sony没有问题兄弟:) –

+0

欢迎大..... – sony

1

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

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