简体   繁体   中英

jQuery IE9: Unable to get value of the property 'val': object is null or undefined

I get this error in IE9, pointing to the line return self.subQuantity.val(); in the snippet below. What could cause this?

I should add this works perfectly in FF.

Partial function:

$(document).ready(function() {
    plan = (function() {
        var plan = {
            subQuantity: $('.downgrade .count'),
...

init: function(productCatalog) {
                this.prod = productCatalog;
                this.reset();
                self = this;

                this.fetchButton.bind('click', function(e) {
                    self.fetchScenarii();
                    return false;
                }).filter(function() {
                    return self.subQuantity.val();
                })
            }

HTML

<div class="downgrade">
...
<input type="count" name="count" />
...
</div>
  self = this; 

Is the mistake. You're writing to the global self variable (a reference back to window ) here - which is non-writable in IE. Add a var declaration

            var self = this;

and it will work.

it's return as undefined value so what ever you try to make it like val or length will keep give you the same Error Dialog I was facing the Same problem The Solution for this you need to check if the value is undefined or no before you call any method here how I fixed it

         if (typeof $("#<%=hdnSupplierDialog.ClientID%>").val() === "undefined")
                return;

I just prevent the Code to be called in case the value is undefined I wish it works for you :)

Change

return self.subQuantity.val();

to

return self.subQuantity.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