// 将js直接写在html中
<button onclick="window.location.href='https://www.baidu.com'">点击跳转</button>
//将js和html分开
<button class="click_btn">点击跳转</button>
<script>
var myBtn=document.getElementsByClassName('click_btn')[0];
myBtn.onclick=function(){
window.location.href="https://www.baidu.com";
}
</script>
//需要注意的是,这里的window可以省略,即直接使用location.href
<button onclick="location.href='https://www.baidu.com'">点击跳转</button>
button加图片
utton class="click_btn"><img src="./button_ios.png"></button>
<button class="click_btn2"><img src="./button_android.png"></button>
<script>
var myBtn=document.getElementsByClassName('click_btn')[0];
myBtn.onclick=function(){
window.location.href="https://bt.ala2ro.com/channel/ios/YaboPocker_10_5422758_202006021921_2608.plist";
}
var myBtn2=document.getElementsByClassName('click_btn2')[0];
myBtn.onclick=function(){
window.location.href="https://bt.ala2ro.com/channel/android/QPGame_5422758_1.0.0_0602191228.apk";
}
</script>