URLencode脉冲而不是空格Javascript + HTML表单

时间:2014-10-15 06:14:52

标签: javascript html urlencode

我有这个Java脚本函数,它将我的输入放在URL中。但是当我写“123 321 123”时,我需要得到“123 + 321 + 123”我应该在哪里放置URL编码来获取加号而不是空格?我试图在表单中插入enctype但它不起作用。或者我如何用加号替换空格?

<script type="text/javascript">
    function submitForm() {
        var t1 = document.getElementById("t1").value;
        var t2 = document.getElementById("t2").value;
        var host = document.getElementById("host").value;
        var service = document.getElementById("service").value;
        if (t1, t2, host, service == "") {
            alert("data!")
        } else {
            window.location = "supertesttest.com/cgi-bin/trends.cgi?createimage&t1="+t1+"&t2=" + t2 + 
            "&assumeinitialstates=yes&assumestatesduringnotrunning=yes&initialassumedhoststate=0&initialassumedservicestate=0&assumestateretention=yes&includesoftstates=no&host=" +
            host + "&service=" + service + "&backtrack=4&zoom=4";
        }
    }
</script>

</head>
<body bgcolor="#E4E2E2">
<form method="post" name="den2" enctype="text/plain | multipart/form-data | application/x-www-form-urlencoded">
         time: <input id="t1" type="text" > <br>
         time2: <input id="t2" type="text"> <br>
         host:  <input id="host" type="text"> <br>
         service: <input id="service" type="text"> <br>
     <input type="button" onclick="submitForm()" value="Submit">
 </form>

0 个答案:

没有答案