简体   繁体   English

如何简化JavaScript中的网站重定向程序

[英]How do I simplify a website redirecting program in javascript

So, my goal was to have it so that when the main button was clicked it would automatically redirect to a certain page in a new tab by doing something along the lines of 因此,我的目标是拥有它,以便在单击主按钮时可以通过执行以下操作来自动重定向到新选项卡中的特定页面:

document.getElementById('mybutton').onclick = function() {
    addselect("List of gems", "gemstones.org")
    addselect("Whatever", "A url"
}

So that it would be very simple to make the tags be created, and then have the program redirect depending on what its InnerHTML was. 这样一来,创建标签就非常简单,然后根据其InnerHTML是什么使程序重定向。

But so far I only have: 但是到目前为止,我只有:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <h1 align="center">Misc Info</h1>
  <p>Select a website to go to.</p>
  <select id="searches">
  </select>
  <br>
  <br>
  <button tyoe="button" id="submit">Go to list</button>
  <script>
  function addWebsite(name, url) {

      var select = document.getElementById('searches');
      var text = document.createTextNode(name);
      var option = document.createElement("OPTION")
      option.appendChild(text);
      select.appendChild(option);

  }
  </script>
</body>
</html>

Now I am stuck and clueless, any suggestions 现在,我陷入了束手无策的任何建议

您是否尝试结合2 onclick函数()?

 <button onclick="function1(); function2()"> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM