Javascript变量值未在警告框中刷新

时间:2015-02-18 13:41:42

标签: javascript jquery

请帮我解决这个问题。问题是当我选择班加罗尔并从第二级选择任何名称并点击按钮而不是结果很好,现在没有刷新页面我选择海德拉巴和二级选择值并点击按钮它仍然显示班加罗尔的价值&# 39;警报中的第二级值。

代码:

<div class="Banglore">
    <select class="second-level-select" id="start_1">
        <option value="">-Select Your Area-</option>
        <option value="Mettuguda">Mettuguda</option>
        <option value="Lingampally">Lingampally</option>
    </select>
</div>
<div class="Hydrabad" >
    <select class="second-level-select" id="start_2">
        <option value="">-Select Your Area-</option>
        <option value="A F Hospital">A F Hospital</option>
        <option value="Abbur">Abbur</option>
    </select>

    

脚本:

function startAjax() {
    var a1 = $("#start_1").val();
    var a2 = $("#start_2").val();
    if(a1 != ''){
        var b = a1;
    }else{
        var b = a2;
    }

    alert(b);

}

$(document).ready(function() {

$('#Rank').bind('change', function() {

    var elements = $('div.container').children().hide(); // hide all the elements

    var value = $(this).val();

    if (value.length) { // if somethings' selected

        elements.filter('.' + value).show(); // show the ones we want
    }

}).trigger('change');
});

了解更多详情:http://jsfiddle.net/72pbbsfy/2/ 谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

window.startAjax = function() {
       var rank = $("#Rank").val();
        var a1 = $("#start_1").val();
        var a2 = $("#start_2").val();
        var b;
        if (rank === 'Banglore') {
            b = a1;
        } else if (rank === 'Hydrabad') {
            b = a2;
        } else {
            b = 'not selected'
        }

        alert(b);

    }