iT邦幫忙

0

關於onclick路徑切換的問題

  • 分享至 

  • xImage
<html>
<head>
<meta charset="utf-8">
<title>增加資料</title>
</head>
<body>
<form action="AddData.php" method="get">
溫度:<input type="text" name="Temp"><br>
濕度:<input type="text" name="Humidity"><br>
<input type="submit" value="送出資料">
</form>
<input type="button" value="查詢資料庫資料"
onclick="location.href='http://192.168.0.15/show.php'">
</body>
</html>

這是我的網頁程式碼,因為沒有固定的ip每次換網路時onclick="location.href='http://192.168.0.15/show.php'">這段的192.168.0.15都要跟著換,請問有甚麼寫法可以不用每次換ip嗎?
show.php的路徑是/var/www/html/show.php
網頁程式都是放在/var/www/html
我面前知道用相對路徑好像可以只是最近才開始學php還不太熟

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
淺水員
iT邦大師 6 級 ‧ 2022-05-05 20:44:54

假設目前頁面是 http://192.168.0.15/aaa/index.php

  1. 連結為 show.php 時會相當於 http://192.168.0.15/aaa/show.php
  2. 連結為 /show.php 時會相當於 http://192.168.0.15/show.php
  3. 連結為 /bbb/show.php 時會相當於 http://192.168.0.15/bbb/show.php
0
打雜工
iT邦研究生 1 級 ‧ 2022-05-06 08:19:44

請問您是用自己的電腦當"測試",所以才沒有固定IP,可以用相對路徑或localhost暫時處理。
如果是內部主機(192.168.x.x),設個固定IP比較適當(主機沒固定IP還蠻怪的),或用DDNS方式,不要用IP了。

我要發表回答

立即登入回答