我可以在一行中使用两个事件吗?

Evi*_*mes 2 jquery

我想要在keyup和change上进行操作.

以下声明适用于keyup事件.我想在更改时复制它.

有没有一种简单的方法来实现这一目标?

$("#YourName").keyup(function() {
    ThisValue = $(this).attr("value");
    if (ThisValue.length > 0) {
        ThisValue = "<b>From:</b><br /> " + ThisValue;
        $("#YourNameValid").html(ThumbsUp);
    } else {
        ThisValue = "";
        $("#YourNameValid").html("");
    }
    $("#YourNameText").html(ThisValue);
});
Run Code Online (Sandbox Code Playgroud)

Sha*_*oli 8

试试这个

$("#YourName").bind('keyup change', function() {
    ThisValue = $(this).val();
    if (ThisValue.length > 0) {
        ThisValue = "<b>From:</b><br /> " + ThisValue;
        $("#YourNameValid").html(ThumbsUp);
    } else {
        ThisValue = "";
        $("#YourNameValid").html("");
    }
    $("#YourNameText").html(ThisValue);
});
Run Code Online (Sandbox Code Playgroud)