English 中文(简体)
贾瓦·里贝里加点的行为不同于手工行为。
原标题:JavaScript click has different behavior than manual one

原型 我在几个检查箱上听了一次点击事件。 在检查箱中,我想要排除所有<代码><select>内容。 使用原型。 因此,我有这一法典:


$$( .silhouette-items input[type="checkbox"] ).invoke( observe ,  click , function(event) {
            var liItem = this.up( li.item );      
            if(this.checked) {
                alert( checked );
                liItem.removeClassName( inactive );
                var selectItem = liItem.select( select );
                for(i=0;i<selectItem.length;i++) {
                    selectItem[i].disabled=false;   
                    if (selectItem[i].hasClassName( super-attribute-select )) {
                        selectItem[i].addClassName( required-entry );
                    }
                }
            } else {
                alert( unchecked );
                liItem.addClassName( inactive );
                var selectItem = liItem.select( select );
                for(i=0;i<selectItem.length;i++){
                    selectItem[i].disabled=true;
                    if (selectItem[i].hasClassName( super-attribute-select )) {
                        selectItem[i].removeClassName( required-entry );
                    }
                }
            }
            calculatePrice();
        });

When I manually click on the checkbox, everything seems to be fine. All elements are disabled as wanted. However, I have also this button which on click event it fires one function which fires click event on that checkbox.

在操作浏览器中,它发挥作用。 在其他情况下,不是。 它像头号(un)剪辑,然后执行活动。 第一次火灾,然后是(un)检查。

我不知道如何解决这一问题。

传真:


<ul class="silhouette-items">
  <li>
    <input type="checkbox" checked="checked" id="include-item-17" class="include-item"/>
    <select name="super_attribute[17][147]">(...)</select>
    <select name="super_group[17]">(...)</select>
    <button type="button" title="button" onclick="addToCart(this, 17)">Add to cart</button>
  </li>
  <!-- Repeat li few time with another id -->
</ul>

另一项联合材料:


addToCart = function(button, productId) {
            inactivateItems(productId);
            productAddToCartForm.submit(button);
        }
inactivateItems = function(productId) {
             $$( .include-item ).each(function(element) {
                var itemId = element.id.replace(/[a-z-]*/,   );
                if (itemId != productId && element.checked) {
                    simulateClickOnElement(element);
                }
                if (itemId == productId && !element.checked) {
                    simulateClickOnElement(element);
                }
            });
        }
simulateClickOnElement = function(linkElement) {
            fireEvent(linkElement,  click );
        }

在<条码>火线是指引发事件的Magento功能

最佳回答

如果你不这样做,则捐赠双筒模拟浮标。 在您的个案中,由外部传来的单独职能可以由活动主管承担。


var handler = function(){
    //...
}
var nodeW = $( #node );
handler.call(nodeW);

当然,这 t可能引发所有浮标处理器,但更简单,这样它就应当做到一切正确。 说明你何时使用职务:

  1. 无论你作为第一个参数通过什么,都作为电话中的this。 我不确切地回顾一下JQuery在this上的写法,但你应尝试通过同样的文字来保持一致性。

  2. 其他参数成为该职能的实际参数。 举例来说,我没有通过,因为我们没有实际使用事件标语,也因为我不知道如何效仿JQuery是如何制造这种物体的。

问题回答

替换

fireEvent(linkElement,  click );

iii

linkElement.click();

烟火5和法文本5.1中的工作,因此问题可能在于火力(火力)方法。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.