我有 2 个选择框。有没有办法在两者都被选中后执行一个动作?
我希望用户从 2 个选择框中选择一个起点和一个目的地,一旦选择了两个值,我就想显示一个价格。
<label>Suburb</label>
<select id="delivery_from_area" name="delivery[from_area]"><option value="">Select</option>
<option value="1">Atlantic Seaboard</option>
<option value="2">City Bowl</option></select>
<label>Suburb</label>
<select id="delivery_to_area" name="delivery[to_area]"><option value="">Select</option>
<option value="1">Atlantic Seaboard</option>
<option value="2">City Bowl</option></select>
我的尝试
$("#delivery_from_area").on("change",function(){
var check1 = $("#delivery_from_area").text();
var check2 = $("#delivery_to_area").text();
if(check1!="" && check2!="") {
var value1 = $("#delivery_from_area option:selected").text();
var value2 = $("#delivery_to_area option:selected").text();
//calculate value
}
});
$("#delivery_to_area").on("change",function(){
var check1 = $("#delivery_from_area").text();
var check2 = $("#delivery_to_area").text();
if(check1!="" && check2!="") {
var value1 = $("#delivery_from_area option:selected").text();
var value2 = $("#delivery_to_area option:selected").text();
//calculate value
}
});