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;
v开发者_JAVA百科ar keyPress = checkBrowser(e);
if (keyPress == 13) {
setDescription();
}
}
Any solutions for it
Here:
onclick="clearDescription();"
you are not passing any argument to the clearDescription
function which expects an e
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:
<input type="text" style="width: 350px; height: 50px;" id="txtDescript" value="Enter Description" class="TextBox" />
and then:
$(function() {
$('#txtDescript').keypress(function(e) {
clearDescription(e);
}).click(function(e) {
clearDescription(e);
}).blur(function(e) {
// As you haven't shown how the blurDescription
// function look like you might want to check the arguments
blurDescription(e);
});
});
which could also be written like this:
$(function() {
$('#txtDescript')
.keypress(clearDescription)
.click(clearDescription)
.blur(blurDescription);
});
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.
精彩评论