1

I have the code below. It works to begin with, but when i change the values it seems to keep the previous values in memory and doesnt do the multiplications i want it to. Can you suggest anything?

var output = $('#SquareMetres');
$('#input[type="text"]').keyup(function() {
    var width = $('#width').val();
    var height = parseFloat($(this).val());
    output.text(height*width);
});

fiddle: http://jsfiddle.net/nRAhE/

4

1 に答える 1

1

このようにしてみてください

$('input[type="text"]').keyup(function() {
    var width = parseFloat( $('#width').val() ),
        height = parseFloat( $('#height').val() ),
        result = height * width;

    if ( ! isNaN( result ) ) {
        output.text( result );
    }
});​

デモ

于 2012-11-30T01:38:25.297 に答える