2011-08-01 9 views
0

私はJqueryとJavascriptを初めて使用しています。この問題に関するヘルプが必要です:Jquery/Javascriptでkeypressイベントを書き込む方法は?

Profileという名前のdivがあります。これをクリックすると新しいポップアップウィンドウが開きます。今これはマウスクリックでのみ可能です。私はそれもキープレス(入力)で行う必要があります。 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の/ JavaScriptコードは

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]  
    }; 

FOR

JSP CODEます(入力)キー入力のための機能を作成する方法を教えますか?

答えて

1

bindあなたとkeypressまたはkeyupイベントが

<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

$("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 
} 
}); 
いくつかのクラスを追加
関連する問題