簡體   English   中英

使用javascript或jQuery導航到其他頁面時如何替換路徑

[英]How to replace path when navigating to other page using javascript or Jquery

我需要一個幫助。這里我想假設用戶當前在個人資料頁面中( http://localhost/medilink/profile.php )。當用戶僅單擊一個按鈕時, profile.php將替換為deal.php ,相應的頁面會來。我需要使用click事件的這種情況,並更改URL獲取新頁面。請幫助我。

您可以將其添加到您的按鈕:

// set the proper url

// relative path :
onclick="window.location.href = './deal.php'"
// absolute path :
onclick="window.location.href = '/medilink/deal.php'"
// other website :
onclick="window.location.href = '//google.com"

您的按鈕(“ a”標簽?或“ button”標簽?)變為:

<button onclick="window.location.href = './deal.php'">my Button</button>

您可以創建一個函數並傳遞要重定向的網址。

// JS:

function redirectURL(url) {
  window.location.href(url)
}

// HTML:

<button onclick="changeURL('http://www.gooogle.com')"></button>

以下代碼段可能會對您有所幫助。

 $('button').click(function () { var arr = window.location.href.split('/'); arr[arr.length - 1] = 'deal.php'; var url = arr.join('/'); window.location = url; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button>click here</button> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM