我有一个特殊的jQuery,它在IE9、Chrome和Firefox等中运行良好,但IE8似乎特别不喜欢它:
<script type="text/javascript">
$("#bandwidth").ForceNumericOnly();
$("#bandwidth").on("input", function() {
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
</script>
这将从带宽输入中获取输入,进行相应计算,然后写入总,前缀为£。
它似乎没有在total输入中执行计算,这真的让我很困惑。
DEMOhttp://jsbin.com/acigaj/2
您可以使用keyup事件此事件在IE7+中运行良好
$("#bandwidth").on("keyup", function() {
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
编辑:如果您想将输入字段仅限于数字?然后你可以做这样的事情。
演示:http://jsbin.com/acigaj/5/edit
$("#bandwidth").on("keyup", function() {
this.value = this.value.replace(/[^0-9]/,'');
var total = this.value*0.18;
$('#total').val('£'+ total.toFixed(2));
});
对于IE8,您可能希望拥有keyup keydown事件或propertychange事件的组合。。。行为类似于输入事件,是从IE6+添加的
也许这会有所帮助:
http://jsbin.com/okusov/2
$(function(){
$('#helloMama').on('propertychange', function(e){
var $this = $(this);
$('#output').text("cought by IE6+ :"+$this.val());
});
$('#helloMama').on('input', function(e){
var $this = $(this);
$('#output').text("cought by smarties: "+$this.val());
});
});