【问题标题】:Jquery EasyUI- How to get checkbox checked or not checked in easyui-datagrid table tdJquery EasyUI-如何在easyui-datagrid表td中选中或不选中复选框
【发布时间】:2018-09-14 06:24:21
【问题描述】:

我是 jeasyui 的新手。我使用 easyui-datagrid 生成了动态表,并且必须为每一行启用复选框。现在我想在选中并取消选中特定行的复选框时获取每一行的详细信息。

<table id="process-list" title="Video Processing" class="easyui-datagrid" style="width:700px;height:250px"
        url="$/emplyoee/getfiles.action"
        idField="itemid">
    <thead>
        <tr>
     <th field='ck' checkbox="true"  type="checkbox" ></th> 
             <th field="id" width="50" >Id</th>              
            <th  field="createDate" width="50" >CreateDate</th>
            <th field="product" width="50">Product</th>             
            <th field="no.Files" width="50">No.Files</th>
            <th field="status" width="50">Status</th>
            <th field="cycle" width="50">Cycle</th>
        </tr>
    </thead>
</table>

$(document).ready(function() { 
$('input[name="ck"]').click(function(){
if($(this).prop("checked") == true){
    alert("Checkbox is checked.");
}
else if($(this).prop("checked") == false){
    alert("Checkbox is unchecked.");
}  

});

我尝试了点击功能,但它不起作用。 });

【问题讨论】:

  • 欢迎来到 Stackoverflow。你试过什么了?请注意,Stackoverflow 不是编码服务。我们希望您完成研究并至少提出一些尝试,在这些尝试中您被困在某个地方并有一个特定的问题。请阅读:stackoverflow.com/help/how-to-askstackoverflow.com/help/mcve
  • @Martin:检查我更新的问题。
  • 我没有看到任何输入,或者实际上根本没有任何元素,名称属性 name="ck" 附加到您的任何元素。
  • 正如@Martin 所提到的,复选框的输入字段在哪里?现在您正在使用 作为您的 的替代品。 .prop("checked") 在这种情况下没有做任何事情,因为您没有检查
  • @radu apostolescu: 生成动态表,输入标签内会生成 tbody,tr,td。

标签: jquery-easyui


【解决方案1】:

$('table').on('click','td input',function(){
if($(this).prop("checked") == true){
    alert("Checkbox is checked.");
}
else if($(this).prop("checked") == false){
    alert("Checkbox is unchecked.");
}  

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <tr>
   <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <tr>
   <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <tr>
   <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <tr>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
  <tr>
   <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
    <td><input type="checkbox"></td>
  </tr>
</table>

【讨论】:

  • 这是 jquery 表。我想要easyui上的datagrid表
  • 尝试在 easyui 上用 datagrid 表替换 jQuery 表。它有效。
  • 不可能...在我的应用程序中,我们正在使用easyui ..在jquery中我知道。但我想要easyui
猜你喜欢
相关资源
最近更新 更多
热门标签