开发者

onkeyup instead of on submit

开发者 https://www.devze.com 2023-03-21 13:25 出处:网络
I\'m using JTube found over here: JTube at github I\'m trying to make a request on keyup instead of on submit. This is the script:

I'm using JTube found over here: JTube at github

I'm trying to make a request on keyup instead of on submit. This is the script:

 var qsParm = new Array();
    function qs() {
        var query = window.location.search.substring(1);
        var parms = query.split('&');
        for (var i=0; i<parms.length; i++) {
            var pos = parms[i].indexOf('=');
            if (pos > 0) {
                var key = parms[i].substring(0,pos);
                var val = parms[i].substring(pos+1);
                qsParm[key] = val;
            }
        }
    }

    $(function() {
        qs();

        if(qsParm['search'] == '' || qsParm['search'] == null || qsParm['search'] == undefined)
            qsParm['search'] = 'splinter cell';
        else
            qsParm['search'] = unescape(qsParm['search']);

        $('input[name=search]').val(qsParm['search']);

        $.jTube({
            request: 'search',
            requestValue: qsParm['search'],
            limit: 10,
            page: 1,
            success: function(videos) {
                $(videos).each(function() {
                    $('#example').append('<li><a href=开发者_Go百科"'+this.link+'"><img src="'+this.thumbnail+'"><br>'+this.title+'</a> - '+this.length+'</li>');
                });
            },
            error: function(error) {
                $('#example').html(error);
            }
        });
    });

As far as I understand the function is ''qs'' So therefore I tried:

$("input").onkeyup(function(){
     qs();
     return false;         
 });

Did not work. I tried many other things with no success. Help is appreciated.


Change it to:

$("input").keyup(function(){
     qs();
     return false;         
 });

jQuery version of onKeyup is called keyup. In general onXXX are the DOM events and jQuery handlers simply do not have on in them.


You need to call the "sendQS" function (which is anonymous in your example) to actually send the data. Also, the jquery function is keyup not onkeyup.

function sendQS() {
    qs();

    if(qsParm['search'] == '' || qsParm['search'] == null || qsParm['search'] == undefined)
        qsParm['search'] = 'splinter cell';
    else
...
}

$("input").keyup(function(e){
     sendQS();
     return false;         
 });


Try something like this:

  $('#target').keyup(function() {
  alert('Handler for .keyup() called.');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消