js 中文本框的按键事件在 firefox 中不起作用
我在这里粘贴我的示例代码,我试图检测按键上的 Enter 键,但它在 FF 中不断给出错误,表明 e 未定义。
$(document).ready(function() {
$('#txtDescript').keypress(function(e) {
clearDescription(e)
});
});
我的标记
<input type="text" style="width: 350px; height: 50px;" id="txtDescript" value="Enter Description"class="TextBox" onclick="clearDescription();"
onblur="blurDescription();" />
这是函数
function clearDescription(e) {
debugger
var KeyID = (window.event) ? event.keyCode : e.keyCode;
var keyPress = checkBrowser(e);
if (keyPress == 13) {
setDescription();
}
}
任何解决方案
I am pasting my sample code here i am trying to detect enter key on key press but it keep giving error in FF that e is undefined.
$(document).ready(function() {
$('#txtDescript').keypress(function(e) {
clearDescription(e)
});
});
My markup
<input type="text" style="width: 350px; height: 50px;" id="txtDescript" value="Enter Description"class="TextBox" onclick="clearDescription();"
onblur="blurDescription();" />
this is the function
function clearDescription(e) {
debugger
var KeyID = (window.event) ? event.keyCode : e.keyCode;
var keyPress = checkBrowser(e);
if (keyPress == 13) {
setDescription();
}
}
Any solutions for it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里:
您没有将任何参数传递给需要
e
参数的clearDescription
函数。另外,因为您使用的是 jquery,所以我不太明白为什么要混合标记和 javascript。这样不是更好吗:然后:
也可以这样写:
话虽如此,您还可以看看 jquery 水印插件 它提供了与我怀疑您正在尝试实现的功能类似的功能。
Here:
you are not passing any argument to the
clearDescription
function which expects ane
argument. Also because you are using jquery I don't really understand why you are mixing markup and javascript. Wouldn't it be better like this:and then:
which could also be written like this:
All this being said, you could also take a look at the jquery watermark plugin which provides similar functionality to what I suspect you are trying to implement.