对象不支持 Internet Explorer 中的 属性 或方法 'previous'
Object doesn't support property or method 'previous' in Internet Explorer
我有一个使用 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();
我有一个使用 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();