1

我有一个单选按钮,我需要使用 Prototype 添加类“validate-one-required-by-name”,但前提是当前 URL 包含文本“/checkout/”

这是我的单选按钮的代码:

<input id="cm1" name="adj[delivery_comment]" value="Ma&ntilde;ana - 10am a 12pm"     title="Ma&ntildeana" class="input-text delivery-comment" type="radio"> <strong>Ma&ntilde;ana</strong> (10am a 12pm)</input>

我对原型很陌生,我已经搜索了好几天,但我找不到解决方案。欢迎任何想法。

谢谢!

4

1 回答 1

2

确保在 DOM 内部加载后执行此操作

document.observe('dom:loaded',function(){
    //after DOM loaded you can manipulate it

    if(window.location.href.include('/checkout/'))
    {
        //If its one that one radio button you can do it like this
        $('cm1').addClassName('validate-one-required-by-name');

        //lets say its any element with the 'delivery-comment' class
        $$('.delivery-comment').invoke('addClassName','validate-one-required-by-name');

        //or all of the radio buttons in the DOM
        $$('input[type="radio"]').invoke('addClassName','validate-one-required-by-name');
    }

});
于 2013-09-15T00:44:52.820 回答