javascript - 使用 html 选择选项值创建动态链接

标签 javascript html

我想创建一个动态链接,其值选自 html 。以下是到目前为止我可以做的示例代码。

<select name="sequence" id="sequence" onChange="document.getElementById('selectedValue').innerHTML = this.value;">
    <option>file1</option>
    <option>file2</option>
    <option>file3</option>

    </select>

    <a href="data/file1"><span id="selectedValue"></span></a>

如何使用所选选项动态创建此链接。

最佳答案

function changeLink(val){
  document.getElementById('selectedValue').innerHTML = val;
  document.getElementById('link').href="data/"+val;
}
<select name="sequence" id="sequence" onChange="changeLink(this.value);">
  <option>file1</option>
  <option>file2</option>
  <option>file3</option>
</select>

<a id="link" href="data/file1"><span id="selectedValue"></span></a>

关于javascript - 使用 html 选择选项值创建动态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31977571/

相关文章:

javascript - 固定在 Yii Bootstrap 中的顶部菜单

javascript - 带有句法着色的 Json Pretty Print

javascript - 指针事件为 null 的元素上的“单击”(或替代方法)

javascript - 我在某些 html 页面开头看到的大块 javascript 是什么?

javascript - JS : karma rollup empty bundle

html - Bootstrap 响应侧边栏调整大小问题

css - 如何获得在 IE8 中工作的输入的底部填充?

php - 替换 HTML 页面中的 iPhone 表情符号

javascript - 当用户点击 "quick replies"按钮时如何打开 webview?

javascript - 保存变量值以备将来在 peg.js 上使用