2
我正在使用google maps API。我的HTML看起来像这样:执行Jquery函数的两个条件()
<form id="searchTheme" method="get">
<select class="form-control" name="thema" id="themaID">
<option value="1">item1</option>
...
<option value="5">item1</option>
</select>
<input type="submit" name="submit" value="zoek">
</form>
<button id="allePois"> Alle POI‘s</button>
我的JavaScript(jQuery的)看起来像这样:
function initMap(x) {
//some other code
var controlUIMijnPOIS = document.getElementById('allePois');
$('#searchTheme').submit(function() {
//CODE to be executed (with the themaID passed by the form)
})
controlUIMijnPOIS.addEventListener('click', function() {
//CODE to be executed (same code as above but themaID has no value, wich is fine)
})
//some other code
}
我可以复制两个事件的代码(表单提交和按钮点击),但我想的一样如果提交表单或点击按钮,则执行代码。 (我不希望有一大堆的代码两次我的脚本)
所以我会得到这样的事情:
$('#searchMyTheme').submit || controlUIMyPOIS.addEventListener('click') function(){
//CODE to be executed.
}
是,即使是可能的,如果是这样,我怎么能建立这个?
你能解释得更清楚吗, – mmativ
请尽量放html代码,以及试图运行什么函数。 – mmativ
你想将2个事件附加到同一个监听器?这似乎是正常的事情。你面临什么问题? – avck