简体   繁体   中英

object.attr('value') returns property value instead of attribute value

I have the following code. When I use firebug to check discountInput, it says: Object [input property value ="77" attribute value="75"]

However, "originalAmount" is 77 and so is "amount". How do I get the attribute value? I want to use it because I need to know what was originally in the input field before it was changed. I am using jquery 1.6.2 for this.

var cell = $(this);
var discountInput = $("input[name=discount]", cell);
var originalAmount = discountInput.attr('value');
var amount = discountInput.val();

You can use the defaultValue property on discountInput .

var cell = $(this);
var discountInput = $("input[name=discount]", cell);
var originalAmount = discountInput[0].defaultValue;
var amount = discountInput.val();
var amount  = $('input[name="discount"]', this).attr("value");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM