0

由于我对使用 php 和 javascript 比较陌生,因此在尝试在 URL 中添加多个变量时遇到了这个问题

我使用以下脚本:

<script>
function refresh() {
 var PCWDE = document.getElementById("PC");
 var NMWDE = document.getElementById("naam");
 var VNMWDE = document.getElementById("voornaam");
 var ONDWDE = document.getElementById("onderneming");
 var BTWWDE = document.getElementById("btwnummer");
 var LNDWDE = document.getElementById("land");


        this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value "&nm=" + NMWDE.value "&vnm=" + VNMWDE.value "&ond=" + ONDWDE.value "&btw=" + BTWWDE.value "&lnd=" + LNDWDE.value;

}
</script>    

这是通过以下 html 代码激活的:

    <?php
    $pc = $_GET['PCS'];
    echo '<input type="text" name="pc" id="PC" onblur="refresh()" value="'.$pc.'">'
    ?>

使用这个 html 代码的主要原因是我需要在不提交表单的情况下执行查询,同时即使在页面刷新时仍然能够保存文本框的值。上面的 html 代码使用不同的 ID 多次使用。

我在尝试这样做时面临的问题是,我的代码仅在仅向 URL 添加 1 个变量时才有效,如下所示:

 this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value;

否则它不起作用。'onblur' 事件无法工作,或者脚本无法运行。

有没有办法以与我现在正在做的类似的方式将多个变量添加到 URL?

4

1 回答 1

1

你忘了加号。这是一个语法错误,如果您打开错误控制台,您应该会看到错误消息。(在 Firefox 上按 control-shift-j)

应该是:

this.document.location.href = "http://example.com/form.php?PCS=" + PCWDE.value + "&nm=" + NMWDE.value + "&vnm=" + VNMWDE.value + "&ond=" + ONDWDE.value + "&btw=" + BTWWDE.value + "&lnd=" + LNDWDE.value;
于 2013-05-30T22:43:17.367 回答