如何使用jquery从复选框到按钮控件获取值 [英] how to get value from checkbox to button control using jquery

查看:45
本文介绍了如何使用jquery从复选框到按钮控件获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码显示如下

 <   div  >  
< id = tblEnquire class = table table-hover table-bordered table-striped table-responsive >
< thead >
< tr >
< th > < / th >
< span class =code-keyword>< th > 学生姓名< / th >
< th > 课程< / th >
< th > 资格认证< / th >
< th > 联系< / th >
< th > 电子邮件< / th >
< th > 地址< / th >
< th > 备注< / th >
< / tr >
< / thead >
< tbody >

@foreach(StudentsEnquire enqire in Model.StudentEnquire)
{
< tr >
<
td > @ Html.CheckBox (status+ enqire.StudentId,new {value = enqire.StudentId,@ class =EnquireCheckBox})< / td >
< td > @(enqire.SName)< / td >
< td > @(enqire.SCourse)< / td >
< < /温泉n> td > @(enqire.SQualification)< ; / td >
< td > @(enqire.SContact)< / td >
< td > @(enqire.email)< span class =code-keyword><
/ td >
< td > @( enqire.SAddress)< / td >
< td > @(enqire.Remarks )< / td >
< / tr >
@ Html.Hidden(studentid,enqire.StudentId)
}

< / tbody >
< < span class =code-leadattribute> / table >
< 按钮 类型 = 按钮 class = btn btn- primary btn-xs id = btnAddNewStudent data-dissmiss = modal > 添加新学生< / button >
< 按钮 type = 按钮 class = btn btn-primary btn-xs id = btnEditStudent data-dissmiss = modal > 编辑学生< / button >
< 按钮 类型 = 按钮 class = btn btn-primary btn-xs id = btnDeleteStudent data-dissmiss = modal > 删除学生< / button >
< / div >





如果我点击一个复选框并点击EditStudent bu tton然后会出现其他对话框,其中包含值以进行编辑。

我正在尝试编写一个jquery,如下所示

 $(' #btnEditStudent')。click( function (){

if ($(' EnquireCheckBox')。checked == true ){
var value = $( this )。val();
data:$( this )。val();
$ .ajax({

url: / Students / UpdateStudent?StudentId = +数据,
成功: function (数据){
$( ' #testbody')。html(data);
$(' #myModal')。modal(' show');

}
});

}

else if ($( this )。prop( checked )== false ){


}

});





这个jquery无效。

解决方案

' #btnEditStudent')。点击( function (){

if


' EnquireCheckBox')。checked == true ){
var value =


this )。val();
数据

hi, i have code show below

<div>
                <table id="tblEnquire" class="table table-hover table-bordered table-striped table-responsive">
                    <thead>
                        <tr>
                            <th></th>
                            <th>Student Name</th>
                            <th>Course</th>
                            <th>Qualification</th>
                            <th>Contact</th>
                            <th>Email</th>
                            <th>Address</th>
                             <th>Remarks</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                          @foreach(StudentsEnquire enqire in Model.StudentEnquire)
                          {
                              <tr>
                                  <td>@Html.CheckBox("status"+enqire.StudentId, new { value = enqire.StudentId, @class = "EnquireCheckBox" })</td>
                                  <td>@(enqire.SName)</td>
                                  <td>@(enqire.SCourse)</td>
                                  <td>@(enqire.SQualification)</td>
                                  <td>@(enqire.SContact)</td>
                                  <td>@(enqire.email)</td>
                                  <td>@(enqire.SAddress)</td>
                                  <td>@(enqire.Remarks)</td>
                              </tr>
                              @Html.Hidden("studentid",enqire.StudentId)
                          }
                        
                    </tbody>
                </table>
                <button type="button" class="btn btn-primary btn-xs" id="btnAddNewStudent" data-dissmiss="modal">Add New Student</button>
                <button type="button" class="btn btn-primary btn-xs" id="btnEditStudent" data-dissmiss="modal">Edit Student</button>
                <button type="button" class="btn btn-primary btn-xs" id="btnDeleteStudent" data-dissmiss="modal">Delete Student</button>
            </div>



if i click one checkbox and click on the EditStudent button then other dialog box will appear with values to edit them.
i'm trying to write a jquery for that as shown below

$('#btnEditStudent').click(function () {
       
            if ($('EnquireCheckBox').checked == true) {
                var value = $(this).val();
                data: $(this).val();
                $.ajax({

                    url: "/Students/UpdateStudent?StudentId="+data,
                    success: function (data) {
                        $('#testbody').html(data);
                        $('#myModal').modal('show');

                    }
                });
                
            }

            else if ($(this).prop("checked") == false) {


            }

        });



this jquery is not working.

解决方案

('#btnEditStudent').click(function () { if (


('EnquireCheckBox').checked == true) { var value =


(this).val(); data:


这篇关于如何使用jquery从复选框到按钮控件获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆