我目前有以下代码来更新网址。我如何将它组合成更强大的东西,这样我就不会重复自己3次了。我只想在其中一个字段发生更改时更新。
$(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;
});
});
答案 0 :(得分:4)
$('#position_select, #device_select, #face_select').change(function() {
var device = $('#device_select').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;
});
你有没有试过这样的事情?
答案 1 :(得分:1)
这种方法怎么样?
ASC LIMIT 0,14
答案 2 :(得分:1)
为什么不将代码封装在函数中?
A
然后您可以随时调用该函数:
physician_profile_city
更好的是,您可以添加第二个函数,以便您的代码更具可读性:
physician_profile_last_name
并在physician_profile_state
上调用此函数:
function updateURL() {
var device = $('#device_select').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;
}