我建议如下:
function makePath(directory, file, domain) {
if (!directory || !file) {
return false;
}
else {
directory = directory.nodeType == 1 ? directory.value : document.getElementById(directory).value;
file = file.nodeType == 1 ? file.value : document.getElementById(file).value;
return newURL = [domain || 'http://' + location.hostname, directory, file].join('/');
}
}
document.getElementById('fileName').onblur = function(){
// using console.log() in the demo
document.location = makePath('directoryPath', this, 'http://example.com');
}
JS 小提琴演示。
以上内容与以下 HTML 一起使用:
<select id="directoryPath">
<option>directoryA</option>
<option>directoryB</option>
<option>directoryC</option>
</select>
<select id="fileName">
<option>file1.html</option>
<option>file2.html</option>
<option>file3.html</option>
</select>