javascript - 制作下拉框链接,具体取决于下拉选择 + 在下拉选择中更改 CSS
问题描述
我有一个包含所有选项的下拉框,还有一个 go 按钮,当没有选择时,它具有 css 样式cursor: not-allowed;
。我现在想要做的是,当我点击下拉菜单上的一个选项时,它会 a) 链接按钮 b) 将 csscursor
样式更改为默认值。我知道这是某种形式,document.getElementById
但我该如何触发呢?这是我到目前为止的代码。
<select>
<option value=1>Option 1</option>
<option value=2>Option 2</option>
<select>
<a id="link" href="#">
<button style="cursor: not-allowed;" id=nextbutton>GO</button>
</a>
<script>
document.getElementById("nextbutton").style.cursor = default
document.getElementById("link").href = "/link"
</script>
谢谢你的帮助!(我是 JS 新手,抱歉。)
解决方案
change(0);
function change(index)
{
if(index==1)
{
document.getElementById("nextbutton").style.cursor ="default"
document.getElementById("link").href = "/link"
}
if(index==0)
{
document.getElementById("nextbutton").style.cursor ="not-allowed"
document.getElementById("link").href = "#"
}
}
<html>
<select onchange="change(this.selectedIndex);">
<option value=1>Default</option>
<option value=2>Link</option>
<select>
<a id="link" href="#">
<button style="cursor: not-allowed;" id=nextbutton>GO</button>
</a>
</html>
推荐阅读
- graphql - NestJS Fastify graphql e2e 测试失败
- css - Css 关键帧和动画无法在 Google Chrome 或 Firefox 上运行
- python - 将不和谐的机器人(python)上传到 Heroku:App 与 buildpack 错误不兼容(我知道它被问了很多)
- python-3.x - Python获取具有相同CSS类的html标签列表
- haskell - 使用 Haskell 'statistics' 包进行线性回归
- google-apps-script - 比较(小于/大于)在谷歌脚本中不起作用
- c++ - 如何在 C++ 中定义“递归”函数类型?
- java - Java Swing:在 JPanel 上向用户显示验证规则
- python - 如何使用 Matplotlib、Tinker 和 SubplotHost 更改标签字体大小?
- regex - 正则表达式匹配不会在 perl 中产生输出