不工作jquery回车键和Shift-Enter键
问题描述:
我的J-Query按键,shift键在Mozilla中无法运行Firefox需要帮助,提前致谢。不工作jquery回车键和Shift-Enter键
J-查询使用:jQuery的1.7.2.min.js
<html><body>
<textarea id = 'text' rows='4' cols='50' style = 'width: 50%;height:15%;' placeholder = 'Enter Post....'></textarea>
</body></html>
<script>
$('#text').keypress(
function(e){
if (e.keyCode == 13 && e.shiftKey) {
alert("a");
}
else if(e.keyCode == 13){
alert("sdf");
}
}
);
</script>
答
将您的代码在文档准备好处理程序 -
$(document).ready(function() {
$('#text').keypress(function (e) {
if (e.keyCode == 13 && e.shiftKey) {
console.log("a");
} else if (e.keyCode == 13) {
console.log("sdf");
}
});
});
答
试试这个
$('#text').keypress(function(event) {
if (event.keyCode == 13 && event.shiftKey) {
alert("shift plus enter");
}
});
不工作.. :( – user246186
我的坏...更新了代码。请你检查? – maj