开发者

jquery change() does not seem to be working

I am trying to accomplish simple calculation on few variables. I need to take the val开发者_开发知识库ue from the

<td class="productprice"> 

and multiply it by the value from the

<input type="text" class="quantityBox" value="1"/>

And, I am using this piece of code to see if the value change to recalculate.

$(".quantityBox").change(function(){
alert("Asdasd");
});

And nothing happens. I am expecting the alert box to appear for now, so I'll just be sure that the change works.

Any ideas? Thank you.


Bind the change function in document ready event.

Something like:

$(function(){
    $(".quantityBox").change(function(){ 
        alert("Asdasd"); 
    }); 
});

Note: I assume you are tabbing/moving out of the textbox to see if the change function is firing.


Assuming that you've attached the handler once the DOM is ready, that should work.

Note that the change event won't fire until focus has left the textbox.


Your code works for me: http://jsfiddle.net/8RsXF/ .

If you want to do the calculation after every keypress use keyup:

$(".quantityBox").keyup(function(){
    alert("Asdasd");
});

http://jsfiddle.net/8RsXF/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜