开发者

How to replace a space in a URL in JavaScript?

开发者 https://www.devze.com 2022-12-18 09:37 出处:网络
These are the 2 relevant lines from a function written in JavaScript: var v_depttime = document.getElementBy开发者_StackOverflowId(\"EDDepttime\").value ;

These are the 2 relevant lines from a function written in JavaScript:

var v_depttime = document.getElementBy开发者_StackOverflowId("EDDepttime").value ;
url = url+"?select_bno="+v_busno+"&select_depttime="+v_depttime ;

It sends the select_depttime as 2010-01-24 14:30:00 and I want it to be an URL encoded string like 2010-01-24%2014:30:00

How is it done in JavaScript?


Use encodeURI or encodeURIComponent.


Use encodeURIComponent:

url = url +
  "?select_bno=" + encodeURIComponent(v_busno) +
  "&select_depttime=" + encodeURIComponent(v_depttime);
0

精彩评论

暂无评论...
验证码 换一张
取 消