对象没有't支持属性或方法'上一个'在Internet Explorer中

Object doesn't support property or method 'previous' in Internet Explorer

本文关键字:上一个 Internet 方法 Explorer 支持 对象 属性      更新时间:2023-09-26

我有一个使用Prototype.js的脚本代码,它会产生一个错误:

$('up-qty-item').observe('click',function(event){
    var currentElement = $('up-qty-item').parentNode.previous();
    var i = 0; //In case we get in to infinite loop
    while(currentElement.type != 'text' && i < 5){
        currentElement = currentElement.previous();
        i++;
    }
    currentElement.value = parseInt(currentElement.value) + 1;
    if ($('down-qty-item').hasClassName('disabled')){
        $('down-qty-item').removeClassName('disabled');
    }
});

当我点击此处的following按钮时:

<button type="button" id="up-qty-item" title="<?php echo $this->__('Add Item') ?>" class="button btn-qty up-qty-item">
    <span>+</span>
</button>  

我在Internet explorer控制台中收到以下错误。它在其他浏览器中正常工作。

SCRIPT438: Object doesn't support property or method 'previous'

如何消除此错误?

我能够使用以下方式消除错误:

...
var currentElement = $($('up-qty-item').parentNode).previous();
...

错误消失了。

引用url:http://prototypejs.org/learn/extensions

// this will error out in IE: 
$('someElement').parentNode.hide();
// to make it cross-browser:
$($('someElement').parentNode).hide();