1

嗨,我有以下 url,我试图从中提取值。

http://xxxxxx.com/Confirm.aspx?vCode=123xyzd33eed&emailAddress=xxx@hotmail.com&

我正在尝试提取 vCode 和 emailAddress 的值以显示在适当的字段中。

 <input type="text" id="Text1" name="validationCode" value="<? echo htmlspecialchars($_GET["validationCode"]); ?>" placeholder="validationCode"/>
        <input type="text" id="emailAddress" name="emailAddress" value="<? echo htmlspecialchars($_GET["emailAddress"]); ?>" placeholder="Email Address" />

上面的代码没有显示 vCode 和 emailAddress 的值。任何想法如何解决它?谢谢

4

2 回答 2

1

http://jsfiddle.net/VgEWt/

function getParameterByName(uel, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(url);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

url = "http://xxxxxx.com/Confirm.aspx?vCode=123xyzd33eed&emailAddress=xxx@hotmail.com&";

alert(JSON.stringify(getParameterByName(url, "vCode")));
alert(JSON.stringify(getParameterByName(url, "emailAddress")));
于 2013-08-08T00:37:53.540 回答
0

使用任一

<?php echo htmlspecialchars($_GET["validationCode"]); ?>

或者

<?= htmlspecialchars($_GET["validationCode"]) ?>

并且不要使用

<? echo htmlspecialchars($_GET["validationCode"]); ?>

此外,您在查询字符串中使用 vCode,因此请确保您使用相同的名称来获取它。

于 2013-08-08T00:31:04.993 回答