var elem = document.querySelector('#myInput')
elem.addEventListener('keydown', function(e) {
if( e.keyCode == 13 ){
console.log('Enter is pressed.')
//add your code
}
}) //使用jQuery
$('#myInput').keydown(function(e){
if( $(e).which == 13 ){
console.log('Enter is pressed.')
//add your code
}
})
监听是js来实现的,对于html是否是html5无关。
监测返回键
if(window.history &&window.history.pushState) {
$(window).on('popstate', function() {
var hashLocation = location.hash
var hashSplit = hashLocation.split("#!/")
var hashName = hashSplit[1]
if(hashName !== '') {
var hash = window.location.hash
if(hash === '') {
alert("你点击了返回键")
}
}
})
window.history.pushState('forward', null, './#forward')
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)