我已经尝试了一些方法来实现这一点,但它只是不起作用。
我从这开始:
$('#display_att').click(function() {
var selected_attribute = $('#first_select2 option:selected').text();
var attr_value = $('#second_select2 option:selected').text();
goMap();
});
我需要的是变量selected_attribute
和attr_value
在函数goMap
中可用。
我尝试使用全局变量,但这似乎不起作用(假设我做得正确)。
答案 0 :(得分:1)
首先,您需要构建goMap
来处理额外的“参数”:
function goMap (selected_attribute, attr_value) {
//do things here
}
然后,在您的点击事件中,将这些变量发送到变量:
$('#display_att').click(function() {
var selected_attribute = $('#first_select2 option:selected').text();
var attr_value = $('#second_select2 option:selected').text();
goMap(selected_attribute, attr_value);
});