选择相同选项时,Fire onchange功能

时间:2014-02-01 13:51:06

标签: javascript

我想在用户同时选择第一个选项或选择相同选项时触发此功能。我试过onclick但它发射太快了。

<div id=sources>
    Source1:
    <select id='source1'>
        <option value="volvo">Volvo</option>
    </select>
    <br/>
    Source2:
    <select id='source2'>
        <option value="honda">Honda</option>
        <option value="volvo">Volvo</option>
    </select>
    <br/>
</div>
var s1 = document.getElementById('source1'),
    s2 = document.getElementById('source2');

var select_sources = function () {
    var sourceX = s1.value,
        sourceY = s2.value;
    var constraints = {
        x: {
            optional: [{
                sourceId: sourceX
            }]
        },
        y: {
            optional: [{
                sourceId: sourceY
            }]
        }
    };
    init(constraints);
};

var init = function (sourceInfos) {
    console.log(sourceInfos);
};

s1.onchange = select_sources;
s2.onchange = select_sources;

谢谢,

0 个答案:

没有答案