Bind onclick to enter key

I have a small search box in a content editor web part on my SharePoint site. The user inputs some text into a text box and then has to CLICK an image which serves as the submit button (clicking the image loads the javascript function onclick.)

This is pretty terrible as you cannot press enter to search.

Is there any way to set up the image or onClick() so that it detects Enter being pressed, like a normal submit button?

Thanks for any help


对于onclick()不,它不是,但你可以使用onkeyup()

yourTextField.onkeyup=function(){
    if(event.keyCode==13){
        //enter pressed!
    }
}
链接地址: http://www.djcxy.com/p/51628.html

上一篇: 进入触发按钮点击?

下一篇: 绑定onclick输入密钥