admin管理员组文章数量:1355574
I'm getting Uncaught ReferenceError: e is not defined.
Input field
<input class="form-control text-right" name="amount" maxlength="45" value="${exp.Amount}" onkeyup='evMoneyFormat( e );' required="required">
Script
<script type="text/javascript">
function evMoneyFormat(evt) {
//--- only accepts accepts number and 2 decimal place value
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /^[0-9]{1,14}\.[0-9]{0,2}$/; // number with 2 decimal places
if (!regex.test(key)) {
theEvent.returnValue = false;
//--- this prevents the character from being displayed
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>
How can i fix this ?
I'm getting Uncaught ReferenceError: e is not defined.
Input field
<input class="form-control text-right" name="amount" maxlength="45" value="${exp.Amount}" onkeyup='evMoneyFormat( e );' required="required">
Script
<script type="text/javascript">
function evMoneyFormat(evt) {
//--- only accepts accepts number and 2 decimal place value
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /^[0-9]{1,14}\.[0-9]{0,2}$/; // number with 2 decimal places
if (!regex.test(key)) {
theEvent.returnValue = false;
//--- this prevents the character from being displayed
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>
How can i fix this ?
Share Improve this question asked Jun 25, 2014 at 3:19 BishanBishan 15.8k53 gold badges172 silver badges268 bronze badges 2-
3
Well, what's
e
doing there? I'd suggest adding the event in JavaScript – elclanrs Commented Jun 25, 2014 at 3:20 -
Do you even need
e
here? – Nikhil Talreja Commented Jun 25, 2014 at 3:23
2 Answers
Reset to default 4I think it should be(the event object is available in the inlined context as event
not as e
)
onkeyup='evMoneyFormat( event );'
Since you have tagged it with jQuery, use a jQuery event handler instead of inlined one
You don't need to pass anything to onkeyup
.
It should just be: onkeyup='evMoneyFormat()';
.
When your handler is called, if you have provided a parameter to your function (which you have: evt
), then the event data will automatically be assigned to the parameter.
You can then use evt
in your handler for the event data.
However, seeing as you've tagged this with jQuery, a simpler way would be:
$(".form-control text-right").keyup(function(evt){
//--- only accepts accepts number and 2 decimal place value
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /^[0-9]{1,14}\.[0-9]{0,2}$/; // number with 2 decimal places
if (!regex.test(key)) {
theEvent.returnValue = false;
//--- this prevents the character from being displayed
if (theEvent.preventDefault) theEvent.preventDefault();
}
});
本文标签: jqueryjavascript Uncaught ReferenceError e is not definedStack Overflow
版权声明:本文标题:jquery - javascript Uncaught ReferenceError: e is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744011027a2575568.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论