如何在JavaScript中替换URL中的空格?

时间:2010-01-27 09:37:04

标签: javascript

这些是用JavaScript编写的函数的两个相关行:

var v_depttime = document.getElementById("EDDepttime").value ;
url = url+"?select_bno="+v_busno+"&select_depttime="+v_depttime ;

它将select_depttime作为2010-01-24 14:30:00发送 我希望它是一个URL编码的字符串,如2010-01-24%2014:30:00

如何在JavaScript中完成?

2 个答案:

答案 0 :(得分:9)

答案 1 :(得分:3)

使用encodeURIComponent:

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