2011-08-01 4 views
0

저는 Jquery와 Javascript를 처음 사용합니다. 이 문제와 관련하여 도움이 필요합니다.Jquery/Javascript에서 keypress 이벤트를 작성하는 방법은 무엇입니까?

Profile이라는 div가 있습니다. 클릭하면 새 팝업 창이 열립니다. 이제는 마우스 클릭만으로 가능합니다. 키 누름 (입력)을 통해 수행해야합니다. 사업부

<div tabindex="0" style="text-decoration:underline" onmouseover="this.style.cursor='pointer';" id="<%=namespace%>_pmProfileName_<%=i%>_" onclick="perfChartConfig_<%=namespace%>.doShowProfilesForElement(this);">Profile</div> 

JQUERY/자바 스크립트 코드

doShowProfilesForElement : function(source){ 

    var callback = {  
    success : function(r) { 
     MO.globals.popups.hideWorkingMsg(); 
     this.argument[0].pe = eval("("+r.responseText+")"); 
     var pe = this.argument[0].pe; 

     var pStr = ''; 
     if(this.argument[1].indexOf("pmProfileName") > 0){ 
      if(pe == null || pe._mosol_AllPerfProfileNames.length==0){ 
       pStr = pStr + "<li>There are no profiles available for the element you selected.</li>"; 
      } else { 
       for(var i=0; i<pe._mosol_AllPerfProfileNames.length;i++){ 
        var profile = pe._mosol_AllPerfProfileNames[i]; 
        var onClick = "onClick=\"perfChartConfig_<%=namespace%>.doProfileSelection(this,'"+this.argument[1]+"');\""; 
        pStr = pStr + "<div style=\"text-decoration:underline\" onmouseover=\"this.style.cursor='pointer';\" "+onClick+" >"+profile+"</div>"; 
        //alert('For profile ['+profile+'] there are '+pe[profile].length+' expressions.');   
       } 
      } 
     } 
     if(this.argument[1].indexOf("slaProfileName") > 0){ 
      if(pe == null || pe.offers.length==0){ 
       pStr = pStr + "<li>There are no SLAs available for the element you selected.</li>"; 
      } else { 
       for(var i=0; i<pe.offers.length;i++){ 
        var profile = pe.offers[i]; 
        var onClick = "onClick=\"perfChartConfig_<%=namespace%>.doProfileSelection(this,'"+this.argument[1]+"');\""; 
        pStr = pStr + "<div style=\"text-decoration:underline\" onmouseover=\"this.style.cursor='pointer';\" "+onClick+" >"+profile+"</div>"; 
       } 
      } 
     } 


     var rp = perfChartConfig_<%=namespace%>.rp; 
     rp.setHeader("Select a Profile you want to chart:"); 
     rp.setBody(pStr); 
     rp.render();  
     rp.show(); 
    },   
    failure : function(r) { 
     MO.globals.popups.hideWorkingMsg(); 
     MO.globals.popups.showMsg("Error", "<h2><span class=\"portlet-msg-error\">Your submission failed</span>"+"<br />Status: " + r.status + "</h2>"); 
    },  
    argument: [this, source.id]  
    }; 

에 대한

JSP 코드를 어떻게 키를 누를 때 (입력)에 대한 함수를 작성하는 말해시겠습니까? 당신이

<div tabindex="0" class="someClass" style="text-decoration:underline" onmouseover="this.style.cursor='pointer';" id="<%=namespace%>_pmProfileName_<%=i%>_" onclick="perfChartConfig_<%=namespace%>.doShowProfilesForElement(this);">Profile</div> 

몇 가지 클래스를 추가 div에 함께

답변

1

bindkeypress 또는 keyup 이벤트

$("div.someClass").bind("keyup",function(e){ 

if(e.keyCode == 13) 
{ 
$(this).click(); 
} 

}); 
1
$("#Profile").keyup(function(e){ 
var code = e.which; 
if(code==13){ 
e.preventDefault(); 

    //Do Stuff 
} 
}); 
관련 문제