将jQuery实现到prototypejs [英] Implement jquery into prototypejs

查看:107
本文介绍了将jQuery实现到prototypejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的magento单页结帐遇到了这个问题. 我要实现的是,当您按完整的命令时,它会在所有内容都已填充并已检查ToS时禁用按钮:

I've got this issue with my magento onepage checkout. I want to implement that when you press complete order it disables the button only when everything is filled in and the ToS are checked:

您按"bestelling plaatsen",但并非所有内容都正确填写,它仍然变为灰色.

you press "bestelling plaatsen" and not everything is filled in correctly it still turns gray.

现在,我有了实现在onepagecheckout脚本中使按钮变为灰色的自定义代码的想法,但是问题是我编写的代码是Javascript,但一页的结账脚本是在prototypejs中.

Now I had the idea to implement the the custom code I used to make the button gray in the onepagecheckout script, but the issue is that the code I wrote is Javascript but the onepage checkout script is in prototypejs.

这是我脚本中的代码;

Here's the code from my script;

jQuery(document).ready(function($){
    var btn = $('#onestepcheckout-button-place-order');
    var btnTxt = $('#onestepcheckout-button-place-order span span span');
    var fewSeconds = 10;

    btn.click(function(){
        btn.prop('disabled', true);
        btnTxt.text('Even geduld A.U.B.');
        btn.addClass('disabled');

        setTimeout(function(){
            btn.prop('disabled', false);
            btnTxt.text('Bestelling plaatsen');
            btn.removeClass('disabled');
        }, fewSeconds*1000);
    });
});

这是我认为应在其中实现的代码;

and this is the code where I think it should be implemented in;

Event.observe('onestepcheckout-button-place-order', 'click', function(e) {
    var form = new VarienForm('one-step-checkout-form');
    var validator = new Validation(this.form);  
    if (validator.validate()) {         
        var element = e.element();
        //disable the button
        element.disabled = true;
        $('one-step-checkout-form').submit();
    }
    else {
        //alert('Error');
    }
});

推荐答案

在PrototypeJS中使用您的代码段

Heres your code snippet in PrototypeJS

document.observe('dom:loaded',function(){
    var fewSeconds = 10;
    $('onestepcheckout-button-place-order').observe('click',function(){
        var textelement = this.down('span span span');
        this.writeAttribute('disabled','disabled');
        textelement.update('Even geduld A.U.B.')
        this.addClassName('disabled');
        setTimeout(function(){
            this.writeAttribute('disabled',false);
            textelement.update('Bestelling plaatsen');
            this.removeClassName('disabled');
        }.bind(this),fewSeconds*1000)
    });

});

我做了一些改进,使代码更简洁

I made some improvements to make the code more concise

这篇关于将jQuery实现到prototypejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆