javascript - 使用列表更改 html 页面白色事件 onchange
问题描述
我的 index.html 上有这个列表
<select id="selectFaq">
<option selected>Selecciona un FAQ</option>
<option value="JavaFAQ.html">Java FAQ</option>
<option value="netFAQ.html">.Net FAQ</option>
<option value="PhpFAQ.html">PHP FAQ</option>
</select>
当用户更改列表中的默认值时,下一个代码的提议会更改当前页面:
window.onload = configuraSelect;
function configuraSelect() {
document.getElementById("selectFaq").selectedIndex = 0;
document.getElementById("selectFaq").onchange = cambiaPagina;
}
function cambiaPagina() {
var elementoSelect = document.getElementById("selectFAQ");
var nuevaPagina = elementoSelect.options[elementoSelect.selectedIndex].value;
if (nuevaPagina != "") {
window.location = nuevaPagina;
}
}
但是,关于句子
var nuevaPagina = elementoSelect.options[elementoSelect.selectedIndex].value;
代码没有返回任何值,我该怎么办?
解决方案
会不会是拼写错误?
而不是这个:
var elementoSelect = document.getElementById("selectFAQ");
尝试这个:
var elementoSelect = document.getElementById("selectFaq");
推荐阅读
- mongodb - 如何通过 ssh 隧道将数据保存到远程 mongoDB?(拒绝连接)
- laravel - 如何在 Eloquent 中编写这个原始查询
- javascript - getPastEvents 未定义(重新)
- visual-studio - .net core .editorconfig 警告未显示在 Visual Studio 错误列表中
- linux - lsb_release:在最新的 Ubuntu Docker 容器中找不到命令
- python - 如何修复TypeError:getText()缺少1个必需的位置参数:python中的'self'?
- sql - Postgresql 选择集合中两列之一的位置
- javascript - 有太多条件会破坏 React 中的 HOC 吗?
- apache-spark - EMR 5.27 上的 pyspark spark 2.4 - 列出文件后集群停止处理
- vue.js - 如何让 axios 拦截器重试原始请求?