2013-04-01 142 views
0

我正在使用Ecwid购物车,并希望根据是否选中单选按钮来隐藏/显示产品中的某些选项。具有相同名称和值的JQuery单选按钮 - 单击单选按钮时显示隐藏div | Ecwid

我的测试产品是在这里:

http://www.farmboutique.com/testproduct1.html#!/~/product/category=5128132&id=21349373

我已经隐藏了一些选择上加载使用JavaScript的网页。

现在我想显示隐藏的选项,当有人单选按钮点击次数:

是(不超过9厘米X9厘米更多)(+£4.50)

的选项下“你需要一个绣花标志”。

加载页面时始终选择默认值“不需要”。

同样,如果有人在页面加载后点击Yes选项,然后通过选择“Not Required”来改变他们的想法,它应该使其他选项再次消失。

的单选按钮的HTML代码“是(不超过9厘米X9厘米)(+£4.50)”和“不需要”是:

<div id="ecwid-productoption-21349373-Do_You_Require_An_Embroidered_Logo-container" class="ecwid-productBrowser-details-optionPanel ecwid-productBrowser-details-optionPanel-radio ecwid-productoption-Do_You_Require_An_Embroidered_Logo-container"> 

    <label class="ecwid-fieldLabel" for="gwt-uid-5">Do You Require An Embroidere​d Logo</label> 

    <div id="gwt-uid-5"><span class="gwt-RadioButton ecwid-productBrowser-details-optionRadioButton ecwid-productoption-Do_You_Require_An_Embroidered_Logo-Yes_:0028no_more_than_9cm_x_9cm:0029" id="ecwid-productoption-21349373-Do_You_Require_An_Embroidered_Logo-Yes_:0028no_more_than_9cm_x_9cm:0029"> 

    <input type="radio" name="21349373-Do You Require An Embroidered Logo" value="on" id="gwt-uid-3" tabindex="0"> 

    <label for="gwt-uid-3"><span class="ecwid-productBrowser-details-optionRadioButton-name">Yes (no more than 9cm x 9cm)</span> 

    <span class="ecwid-productBrowser-details-optionRadioButton-price"> <span class="ecwid-productBrowser-details-optionRadioButton-bracket">(</span> 

    <span class="ecwid-productBrowser-details-optionRadioButton-sign">+</span> 

    <span>£</span>4.50<span class="ecwid-productBrowser-details-optionRadioButton-bracket">)</span></span></label></span> 

    <span class="gwt-RadioButton ecwid-productBrowser-details-optionRadioButton ecwid-productoption-Do_You_Require_An_Embroidered_Logo-Not_Required" id="ecwid-productoption-21349373-Do_You_Require_An_Embroidered_Logo-Not_Required"> 

<input type="radio" name="21349373-Do You Require An Embroidered Logo" value="on" id="gwt-uid-4" tabindex="0" checked=""> 

<label for="gwt-uid-4"><span class="ecwid-productBrowser-details-optionRadioButton-name">Not Required</span></label></span></div></div> 

21349373在上面是产品ID = page.productId

回答

0

我认为你可以这样做。主要的问题是我找不到任何有效的选择器来定位你的单选按钮,因为它的名字中有空格,我不能确定生成的id不会改变。尝试在元素上添加一些静态属性,以便更容易查询它们。如果您无法控制idname属性,则可以添加一些其他自定义属性。

$(function() { 
    //get a reference to your hidden div 
    var $divIfRequired = $('[id*=If_you_require_a_logo_to_be]'); 

    //add a click handler on your radio button 
    $('put_some_selector_here').click(function() { 
     //show or hide the div based on the checked status of the radio button 
     $divIfRequired[this.checked? 'show': 'hide'](); 
    }); 
});