[英]How can I make a button redirect my page to another page using a controller action and passing a value using javascript?
[英]How can I make a button redirect my page to another page using addEventListener?
目前,在搜索互聯網后,我想到了以下代碼:
function button(){
var button= getElementById("Sailthru");
button.addEventListener(MouseEvent.CLICK, onClick, false, 0, true)
function onClick(e:MouseEvent):void{
navigateToURL(new URLRequest("http://www.sailthru.com/"), "_blank");
};
盡管它不起作用,但我不確定如何進行。 如果沒有辦法使用它來工作,那么我會很樂意使用另一種方法。 但是,由於我已經研究了一段時間,所以我想使用這種方法。
這是什么語言的組合?
使用普通香草javascript進行此操作的最簡單方法是這樣的:
var button = document.getElementById("Sailthru");
button.addEventListener("click", function(){
document.location.href = 'http://www.sailthru.com';
});
或者,這使用HTTP重定向。
HTML
<button id="btn">
Click
</button>
JS
btn.onclick = function() {
window.location.replace("http://www.sailthru.com/");
}
你可以試試
window.open或window.location根據您的需求
window.open(' http ://test.com','_ blank');
window.location =“ http://test.com”;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.