在div中设置.keyup()

时间:2016-12-09 16:33:07

标签: jquery asp.net webforms

我在ASP.NET WebForm上开发了一个系统。由于它不支持多种表单,因此我使用这些代码在界面中显示为2个表单,按id获取值并按ajax提交值。但在这里,我想为2个虚拟表单设置2个单独的.keyup()函数。有可能吗?如果是,那怎么办?

<!--First form-->
<div class="x_content form-horizontal form-label-left" id="info">
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">E-mail</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="text" class="form-control required" id="email" placeholder="Enter email" readonly>
        </div>
    </div>
    <br />
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">Full Name</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="text" class="form-control required" id="name" placeholder="Enter full name">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">Contact</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="text" class="form-control required" id="contact" placeholder="Enter contact">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
            <button type="button" class="btn btn-primary" onclick="verifyInfo()">Submit</button>
            <button type="button" class="btn btn-danger">Cancel</button>
        </div>
    </div>
</div>


<!--Second form-->
<div class="x_content form-horizontal form-label-left" id="pass">
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">Old Password</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="password" class="required form-control" id="oldpassword" placeholder="Type old password">
        </div>
    </div>
    <br>
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">New Password</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="password" class="required form-control" id="newpassword" placeholder="Type new password">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12">Re-Type Password</label>
        <div class="col-md-9 col-sm-9 col-xs-12">
            <input type="password" class="required form-control" id="repassword" placeholder="Re-type new password">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
            <button type="button" class="btn btn-primary" onclick="verifyPass()">Submit</button>
            <button type="button" class="btn btn-danger">Cancel</button>
       </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:1)

你可以给jQuery Hotkeys一个机会。它非常易于使用,可以处理您的键盘事件。

将Ctrl + m绑定到几个函数[f1和f2],例如:

$('#form1').on('keyup', null, 'ctrl+m', f1);
$('#form2').on('keyup', null, 'ctrl+m', f2);

答案 1 :(得分:0)

在这里,我找到了这个问题的2个答案。 1来自fnostro的评论,

$("#info :input").keyup( function(){...})

另一个是添加2个不同的类,每个:input有2种不同的形式和这个函数。

$('.classname').keyup(function(){
    //
});