我想要输入的值等于ed Or d Or i Or ei之一完成操作。我无法在第一个运行页面中更改值输入value="ed"。我该怎么办?

示例:http://jsfiddle.net/ZsYdY/3/

<input type="text" value="ed">
<div class="code"></div>


function ticket_check() {
    //var val = 'ticket_code=' + $('.ticket_code').val();
    var input_val = $('input').val();
    if (input_val == 'ed Or d Or i Or ei') {
        $('.code').empty().hide().fadeIn('slow').append('It is ok');
    } else {

            $('.code').fadeOut('slow', function () {
                $(this).hide().fadeIn('slow').append('It is not ok');
            })

    }
}

$('.input').live('keyup change', function () {
    ticket_check();
    var input_val = $('input').val();
    if (input_val == 'ed Or d Or i Or ei') {
        $('.code').fadeOut('slow', function () {
            $(this).hide().fadeIn('slow').append('It is not oooooooookkkkkkkkk');
        })
    }
});
ticket_check()

最佳答案

if (input_val == 'ed Or d Or i Or ei') {


需要是:

if (input_val == 'ed' || input_val == 'd' || input_val == 'i' || input_val == 'ei') {


在您的示例中,$('.input')应该为$('input')

Updated Example

关于javascript - 为什么`keyup`和`if`在我的代码中不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7769749/

10-13 04:27