下拉使用javascript选择的值?

时间:2015-09-09 14:08:56

标签: javascript jquery html

我使用了一个包含四种类型值的下拉列表

1.anually
2.semianually
3.quarterly
4.Monthly

其值始终使用anually ICON更改,默认值为semianually。如果用户将其更改为A,则ICON会将s更改为<div class="modal"id="mymodal1" role="dialog"> <div class="pop-dialog"> <!-- Modal content--> <div class="pop-info"style="top: 100px;width:220px"> <div class="pop-header"> <button id="Button1" class="pop-closebtn shadow-inset pull-right" data-dismiss="modal"> X</button> <p>&nbsp</p> </div> <select name="monthlymipfrequency" id="myForm1" > <option value="monthly" name="a" id="monthly1" >Monthly</option> <option value="quarterly" name="a" id="quarterly1" >Quarterly</option> <option value="semianually" name="a" id="semianually1" >Semi Anually</option> <option value="anually" name="a" id="anually1" selected >Anually</option> </select> <!-- </div>--> <div class="pop-footer"> <button id="cancel" class="dont-compare shadow-inset" data-dismiss="modal">Cancel</button> <button id="trigger1" type="button" class="dont-compare shadow-inset">Save</button> </div> </div> </div> </div> 。这是我的选择选项代码:

 var id;
var eve;
var ImageName;
function changeperiod1(event, _id, _src) {
    id = _id;
    eve = event;
    //alert(_id);
    var img = _src.substring(_src.lastIndexOf('/') + 1);
    ImageName = img;
   $('#mymodal1').modal()
    if (ImageName == "A.png") {
        //alert(ImageName);
        $("#anually1").prop('checked', true);
        $("#semianually1").prop('checked', false);
        $("#quarterly1").prop('checked', false);
        $("#monthly1").prop('checked', false);
    }
    if (ImageName == "Q.png") {
        //alert(ImageName);
        $("#quarterly1").prop('checked', true);
        $("#anually1").prop('checked', false);
        $("#semianually1").prop('checked', false);
        $("#monthly1").prop('checked', false);

    }
    if (ImageName == "S.png") {
        // alert(ImageName);
        $("#semianually1").prop('checked', true);
        $("#quarterly1").prop('checked', false);
        $("#anually1").prop('checked', false);
        $("#monthly1").prop('checked', false);

    }
    if (ImageName == "M.png") {
        //alert(ImageName);
        $("#monthly1").prop('checked', true);
        $("#semianually1").prop('checked', false);
        $("#quarterly1").prop('checked', false);
        $("#anually1").prop('checked', false);

    }
    // $('#save').hide();
    $('#trigger1').prop('disabled', true);
    $('#trigger1').addClass('disabledButton');
  }
var value;
$('#myForm1 input').on('change', function () {
    value = $('input[name="a"]:checked', '#myForm1').val();
    $('#trigger1').prop('disabled', false);
    $('#trigger1').removeClass('disabledButton');
});
$('#trigger1').on('click', function () {
    if (value == "anually") {

        $(eve.target).attr("src", "Content/Images/A.png");


    }
    if (value == "semianually") {
        $(eve.target).attr("src", "Content/Images/S.png");

    }
    if (value == "quarterly") {
        $(eve.target).attr("src", "Content/Images/Q.png");

    }
    if (value == "monthly") {
        $(eve.target).attr("src", "Content/Images/M.png");

    }
    $('#mymodal1').modal('hide');
});

我有四个选项值。这是我的剧本

function toObject(arr) {
   var rv = {};
   for (var i = 0; i < arr.length; ++i)
   rv[i] = true;
   return rv;
}

它没有用,我犯了什么错误?请帮我。我的Jsfiddle链接:https://jsfiddle.net/htcLcu4d/

0 个答案:

没有答案