0

HTML

<table>
    <tr>
        <td style="align-content: center">
            <select id="start-lunch-hour" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-hour" tabindex="-1" data-inline="true" data-icon="false">
                <option value="13">--</option>
                <option value="1">01</option>
                <option value="2">02</option>
                <option value="3">03</option>
                <option value="4">04</option>
                <option value="5">05</option>
                <option value="6">06</option>
                <option value="7">07</option>
                <option value="8">08</option>
                <option value="9">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12" selected="selected">12</option>
            </select>
        </td>
        <td style="align-content: center">
            <fieldset data-role="controlgroup" data-type="horizontal">
                <select id="start-lunch-minute-digit1" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-minute-digit1" tabindex="-1" data-scroll="true" data-inline="true" data-icon="false">
                    <option value="13">--</option>
                    <option value="0" selected="selected">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select>
                <select id="start-lunch-minute-digit2" data-native-menu="false" data-overlay-theme="d" data-theme="b" name="start-time-minute-digit2" tabindex="-1" data-scroll="true" data-inline="true" data-icon="false">
                    <option value="13">--</option>
                    <option value="0" selected="selected">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                </select>
            </fieldset>
        </td>
    </tr>
</table>

jQuery

$(function () {
        $("#start-time-hour").change(function () {
            var data = $(this).find(":selected").val();
            //alert(data);
            if (data == 13) {
                // This field will be output.
                if ($("#start-time-minute-digit1").find(":selected").val() != 13) {
                    $("#start-time-minute-digit1").val(13).prop('selected', true);                        
                }
                if ($("#start-time-minute-digit2").find(":selected").val() != 13) {
                    $("#start-time-minute-digit2").val(13).prop('selected', true);
                }
                //alert($("#start-time-minute-digit1").find(":selected").val());
                //alert($("#start-time-minute-digit2").find(":selected").val());
            }
            else {
                // This is normal digit input value selection for time from dropdown.
            }
        });
    });

有三个选择(值属性与显示的文本相同) start-time-hour options --,0,1,2.....9 start-time-minute-digit1 options --,0,1,.. .5 start-time-minute-digit2 选项 --,0,1,2.....9

在将其中任何一个更改为“--”选项时,其他两个必须更改为“--”。我写了上面的函数。调试显示值已更改,但页面上的显示文本未更新。当前在 .net C# mvc3 中使用 jQuery mobile。

4

3 回答 3

1

这应该足够了:

if (data == 13) {
    $("#start-time-minute-digit1, #start-time-minute-digit2").val(13);
}

'#' 的选择器错误应该是:

$('#start-lunch-hour')

或者:

$('select[name=start-time-hour]')
于 2013-09-08T11:05:40.333 回答
1

你可以这样做:

function setSelectedOption(selectID, valueToSelect){

    $("#" + selectID + " option[value='" + valueToSelect + "']").attr('selected', 'selected');    
    $("#" + selectID).selectmenu('refresh');
}

$("#start-lunch-hour").change(function () {
    var data = $(this).val();     
    if (data == 13) {
        setSelectedOption("start-lunch-minute-digit1",13);   
        setSelectedOption("start-lunch-minute-digit2",13);   
    } 
});

在这里工作小提琴:http: //jsfiddle.net/REthD/25/

我希望它有所帮助。

于 2013-09-08T11:18:43.247 回答
1

只需将您的 id 更改start-time-minute-digit1start-lunch-minute-digit1, start-time-minute-digit2tostart-lunch-minute-digit2start-time-hourtostart-lunch-hour

DEMO FIDDLE

于 2013-09-08T11:11:14.813 回答