我目前有以下代碼來更新URL。我如何將這個結合成更強大的東西,以便我基本上不重複自己3次。我只希望在更改其中一個字段時更新它。你怎麼聽javascript的多個領域的變化?
$(document).ready(function(){
$('#device_select').change(function() {
var device = $(this).val();
var face = $('#face_select').val();
var position = $('#position_select').val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
$('#face_select').change(function() {
var device = $('#device_select').val();
var face = $(this).val();
var position = $('#position_select').val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
$('#position_select').change(function() {
var device = $('#device_select').val();
var face = $('#face_select').val();
var position = $(this).val();
document.getElementById("add_dev_rack").href="127.0.0.1:8080/dcim/devices/"+device+"/edit/?face="+face+"&position="+position;
});
});
完美爲我的scenerio。謝謝! – csling