2013-08-13 2 views
1

"jquery.keynav.js"항목을 선택하기 위해로드 된 플러그인 중 하나 인 "입력"을 클릭하면 아약스 액션을하고 싶습니다. 누구나 할 줄 알아?아약스의 Keydown 이벤트가 가능합니까?

jQuery를

var main = function() { 
    var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?"; 

    $.ajax({ 
     type: 'GET', 
     url: url, 
     async: false, 
     jsonpCallback: 'jsonCallback', 
     contentType: "application/json", 
     dataType: 'jsonp', 
     success: function (json) { 
      var titles = json.query.results.channel.item.map(function (item) { 
       return item.title; 

      }); 

      var urls = json.query.results.channel.item.map(function (item) { 
       return item.origLink; 

      }); 

      $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>')); 
      $(".container-list-podcast ul li").each(function (key, value) { 
       var text = $(this).text(); 
       $(this).html('<a class="link-podcast" href="' + urls[key] + '">' + text + '</a>'); 
      }); 

      a = $('.nav_holder li a').keynav(function() { 
       return window.keyNavigationDisabled; 
      }); 


     }, 
     error: function (e) { 
      console.log(e.message); 
     } 
    }); 

}(jQuery); 

...

jsfiddle

+0

를 사용해야 계속? keydown 이벤트에서'main' 함수를 호출 하시겠습니까? –

답변

1

당신은 당신이 뭘 하려는지 키 코드

$("#elementId").keypress(function (e) { 
    if (e.keyCode == 13) { 
     alert('Enter key pressed!'); 
     //TODO: call Ajax here 
    } 
}); 
+0

"$. 아약스"전에 올 것인가? 덕분에 . –

+0

예 : 내 예를 봐 : http://jsfiddle.net/shuZm/ –

+0

else if (e.keyCode == 13) { $ ('. 컨테이너 목록 -podcast'). , 기능 (e) { e.preventDefault(); $ ('. 비디오'). attr ('src', this.href); }); } ' 무엇이 잘못 되었나요? –

관련 문제