javascript - 将按钮点击内容替换到另一个网页

标签 javascript html

我是 javascript 的新手和堆栈溢出,只是想知道这是否是将按钮 onclick 中的内容替换到另一个页面的正确方法?因为它在我的情况下不起作用。这是我的代码:

JavaScript:

function newpage(){
    var oldHTML = document.getElementById('cambtn').onclick;
    var newHTML = "window.location='http://curv.info";
    document.getElementById('cambtn').onclick = newHTML;
}

html:

<button name="cambtn" onclick="camera();"><img id="camicon" src="Glitcher-03.png" alt="Camera" width="120" style="position:absolute; left:50px; top:50px;"></button>
<button name="btn" onclick="newpage()"></button>

最佳答案

一般方法:

JS:

function newPage(){
    document.getElementById("cambtn").onclick=function(){
      window.location.assign("http://curv.info");
    };
}

HTML:

<button id="cambtn">...</button>
<button onclick="newPage();">Go</button>

关于javascript - 将按钮点击内容替换到另一个网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13505918/

相关文章:

css - 具有 100% 高度和滚动内容区域的侧边栏

html - 列背景颜色太多

javascript - 在 For 循环中使用选定的选项值

javascript - 如何使用 _.where 通过 ID 查找嵌套在对象数组中的对象?

javascript - 浏览器发送已缓冲视频数据的请求

javascript - 使用 <img> onclick 触发 js 函数

html - 主页链接到 Wordpress 中的仪表板

javascript - 获取数组中选定对象的索引

javascript - jQuery Mobile 禁用某些标签的增强功能?

javascript - 表单内部 'input type file' 和 'dropdown options' 的验证(使用 angularjs)可能吗?