簡體   English   中英

顯示從 URL 到 html 的數據

[英]display Data from URL to html

這是網址

https://www.mystore.com/receipt.html?total=100&orderid=ab123

我想將上面 url 中“total”和“orderid”的值顯示到 html 頁面中的下面代碼中。

<img src="https://getcurcumin.go2cloud.org/aff_l?order=[orderid]&amount=[total]" width="1" height="1" />

所以實際的代碼將讀作

<img src="https://getcurcumin.go2cloud.org/aff_l?order=ab123&amount=100" width="1" height="1" />

從 URL 取值后

我可以使用什么 javascript 代碼? 請建議。

謝謝

嘗試這個:

<script type="text/javascript">
var total = getQueryVariable("total");
var orderid = getQueryVariable("orderid");
alert(total);
alert(orderid);
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}
</script>
var query = window.location.search.split('&'),
    total = query[0].split('=')[1],    // "100"
    orderid = query[1].split('=')[1];  // "ab123"

暫無
暫無

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

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