1

这里有很多关于这个的答案,我试图修改它们以适应但它不起作用。

我为它做了一个 jsfiddle:http: //jsfiddle.net/DrPz4/

选择箱码:

<div class="options">
    <h2>Available Options</h2>
    <br />
    <div id="option-230" class="option">
        <span class="required">*</span>
        <b>Size:</b><br />
        <select name="option[230]">
            <option value=""> --- Please Select --- </option>
            <option value="28">Size 10                        </option>
            <option value="29">Size 12                        </option>
            <option value="30">Size 14                        </option>
            <option value="32">Size 16                        </option>
            <option value="31">Size 18                        </option>
            <option value="117">Made to Measure                        </option>
        </select>
    </div>
    <br />
    <div id="option-253" class="option">
        <b>Bust (cm):</b><br />
        <input type="text" name="option[253]" value="" class="input-text" />
    </div>
    <br />
    <div id="option-254" class="option">
        <b>Waist (cm):</b><br />
        <input type="text" name="option[254]" value="" class="input-text" />
    </div>
    <br />
    <div id="option-255" class="option">
        <b>Hips (cm):</b><br />
        <input type="text" name="option[255]" value="" class="input-text" />
    </div>
    <br />
</div>

JS:

var MTM = jQuery('#option[230]');
var select = this.value;
MTM.change(function () {
    if ($(this).val() == '117') {
        $('#option-253').show();
        }
    else $('#option-253').hide();
});

谢谢

4

2 回答 2

2

You are trying to select without id in jquery

First of all define Id on select control like as below

 <select name="option[230]" id="option--230">

And use as below:

jQuery('#option--230').change(function () {
    if ($(this).val() == '117') {
        $('#option-253').show();
        }
    else $('#option-253').hide();
});

then use as

jQuery('select[name="option[230]"]').change(function () {
    if ($(this).val() == '117') {
        $('#option-253').show();
        }
    else $('#option-253').hide();
});

Demo

于 2013-09-29T02:54:10.050 回答
0

Your selector is wrong. The selector you used #option[230] will select an element with id option and attribute 230 like <select id="option" 230>..</select>.

In this case you can use the name of the select element as the selector as given below...

var MTM = jQuery('select[name="option[230]"]');
MTM.change(function () {
    $('#option-253').toggle(this.value == 117);
    $('#option-254').toggle(this.value == 117);
    $('#option-255').toggle(this.value == 117);
}).change();

Demo: Fiddle

于 2013-09-29T02:54:12.383 回答