简体   繁体   English

动态表在选中FORM文本字段中的显示值以进行编辑时,单击带有相关行的复选框

[英]Dynamic table Click checkbox with associated row when checked show value in FORM textfield to edit

Kindly assist. 请协助。 All I want to do is use to checkbox so when 'checked' it shows the data in the fields so a user can edit. 我要做的就是使用复选框,以便在“选中”时在字段中显示数据,以便用户进行编辑。

This is my JavaScript 这是我的JavaScript

<script type="text/javascript">
$(document).ready(function(){
    $(".add-row").click(function(){
        var OS = $("#OS").val();
        var vCPU = $("#vCPU").val();
        var Memory = $("#Memory").val();
        var Val = $("#Val").val();
        var Performance = $("#Performance").val();
        var HighWrite = $("#HighWrite").val();
        var markup 
        = "<tr><td><input class='checkEdit' type='checkbox' name='record'></td><td>" + OS + "</td><td>" + vCPU + "</td><td>" + Memory + "</td><td>" + Val + "</td><td>" + Performance + "</td><td>" + HighWrite + "</td></tr>";

        $("table tbody").append(markup);
    });

    // Find and remove selected table rows
    $(".delete-row").click(function(){
        $("table tbody").find('input[name="record"]').each(function(){
            if($(this).is(":checked")){
                $(this).parents("tr").remove();
            }
        });
    });

});    

that builds the dynamic table when i fill out the form fields and click the button 'Add' in the image. 当我填写表单字段并单击图像中的“添加”按钮时,将构建动态表。

Table preview 表格预览 在此处输入图片说明

Need add click event in checkbox onclick='handleClick(this);' 需要在复选框中添加点击事件onclick='handleClick(this);' make all data input. 进行所有数据输入。

in handleClick function need toggle input disable base on the checkbox is checked or not. handleClick函数中是否需要基于复选框切换输入禁用。

 $(document).ready(function(){ $(".add-row").click(function(){ var OS = $("#OS").val(); var vCPU = $("#vCPU").val(); var Memory = $("#Memory").val(); var Val = $("#Val").val(); var Performance = $("#Performance").val(); var HighWrite = $("#HighWrite").val(); vCPU =10; var markup = "<tr><td><input class='checkEdit' type='checkbox' name='record' onclick='handleClick(this);'></td><td>" + "<input type='text' class='enable' name='vCPU' value="+vCPU+" readonly>" + "</td></tr>"; $("table tbody").append(markup); }); // Find and remove selected table rows $(".delete-row").click(function(){ $("table tbody").find('input[name="record"]').each(function(){ if($(this).is(":checked")){ $(this).parents("tr").remove(); } }); }); }); function handleClick(cb) { if(cb.checked){ $(cb).parent().parent().find(".enable").each(function(){ console.log($(this)); $(this).prop('readonly', false); }); } else{ $(cb).parent().parent().find(".enable").each(function(){ console.log($(this)); $(this).prop('readonly', true); }); } } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <tbody></tbody> </table> <button class="add-row">add</button> 

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

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