0

我有一些输入(文本类型)。除了一个之外,我想对所有人都采取相同的行为。

我试过这个:

$(document).ready(function() {

    $("input[type=text]").bind('keydown', function(e) {
        ....
    });

    $("#MyOtherInput").keydown(function(e) {
        .....
    });

});

MyOtherInput 是具有特定行为的输入类型 texte ....

你可以帮帮我吗 ?

谢谢,

4

3 回答 3

1

试试这个:

$('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e)
{
    ............
});

它将选择除 myotherinput 控件之外的所有文本类型的输入。试试下面的示例。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

</head>
<body>
    <div id="testdiv">
        <input id="Text1" type="text" /><br />
        <input id="Text2" type="text" /><br />
        <input id="Text3" type="text" /><br />
        <input id="Text4" type="text" /><br />
        <input id="Text5" type="text" /><br />
        <input id="Text6" type="text" /><br />
        <input id="MyOtherInput" type="text" />
    </div>
</body>

<script type="text/javascript">

    $(function()
    {
        $('input[type=text]').not('input[type=text]#MyOtherInput').bind('keydown', function(e)
        {
            alert('Common for all ');
        });

        $('input[type=text]#MyOtherInput').bind('keydown', function(e)
        {
            alert('Only for MyOtherInput');
        });        

    });

</script>

</html>
于 2009-09-19T17:40:06.007 回答
0

只需在需要特定事件的字段上取消绑定事件即可。

$("#MyOtherInput").unbind("keydown").keydown(function(){});
于 2009-09-19T17:24:16.600 回答
0

可以使用类名获取输入框,然后使用

$(document).ready(function() {

    $(".InutClass").bind('keydown', function(e) {
        ....
    });

});

上面的代码将绑定所有具有 InputClass 的元素,输入字段的 css 类。

于 2009-09-20T12:45:12.127 回答