Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询字符串Javascript_Javascript - Fatal编程技术网

查询字符串Javascript

查询字符串Javascript,javascript,Javascript,使用javascript,如何向查询字符串添加一些数据 基本上,我想将window.screen.height和window.screen.width信息添加到查询字符串中,这样我就可以用电子邮件发送其他登录信息 或者,我如何用相同的数据填充两个隐藏字段,一个表单正在提交,这样我就可以从那里提取它了 谢谢,R.对于隐藏字段,请给每个字段一个ID,然后执行此操作 $(“#fieldID”).attr(“value”)=someValue 更新:抱歉,我看到了查询,这让我想到了jQuery。对于隐藏

使用javascript,如何向查询字符串添加一些数据

基本上,我想将window.screen.height和window.screen.width信息添加到查询字符串中,这样我就可以用电子邮件发送其他登录信息

或者,我如何用相同的数据填充两个隐藏字段,一个表单正在提交,这样我就可以从那里提取它了


谢谢,R.

对于隐藏字段,请给每个字段一个ID,然后执行此操作

$(“#fieldID”).attr(“value”)=someVal
ue


更新:抱歉,我看到了查询,这让我想到了jQuery。

对于隐藏字段,给每个字段一个ID,然后执行此操作

$(“#fieldID”).attr(“value”)=someVal
ue


更新:抱歉,我看到了查询,这让我想到了jQuery。

我认为后一个选项更容易实现。例如,如果您有如下隐藏字段:

...
<input type="hidden" name="screenheight" id="screenheight" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" />
...
。。。
...
那么JavaScript将是:

<script type="text/javascript">
document.getElementById('screenheight').value = window.screen.height;
document.getElementById('screenwidth').value = window.screen.width;
</script>

document.getElementById('screenheight')。值=window.screen.height;
document.getElementById('screenwidth')。value=window.screen.width;

我认为后一个选项更容易实现。例如,如果您有如下隐藏字段:

...
<input type="hidden" name="screenheight" id="screenheight" value="" />
<input type="hidden" name="screenwidth" id="screenwidth" value="" />
...
。。。
...
那么JavaScript将是:

<script type="text/javascript">
document.getElementById('screenheight').value = window.screen.height;
document.getElementById('screenwidth').value = window.screen.width;
</script>

document.getElementById('screenheight')。值=window.screen.height;
document.getElementById('screenwidth')。value=window.screen.width;

您也可以使用来玩querystring。

您也可以使用来玩querystring。

如果您想以与库无关的方式将其添加到位置,可以执行以下操作:

var query = window.location.search;
var sep = "?";
if (query) {
   sep = "&";
}
window.location = window.location + sep + "h=" + 
    window.screen.height + "&w=" + window.screen.width;

当然,这假设查询字符串中还没有w或h参数。

如果要以与库无关的方式将其添加到位置,可以执行以下操作:

var query = window.location.search;
var sep = "?";
if (query) {
   sep = "&";
}
window.location = window.location + sep + "h=" + 
    window.screen.height + "&w=" + window.screen.width;

当然,这假设查询字符串中还没有w或h参数。

您想在哪里添加查询字符串?到表单操作属性或某个位置的链接?您希望在哪里添加查询字符串?到表单操作属性或某个地方的链接?jQuery很好,但它需要jQuery:)。仍然无效,因为您需要在#fieldIDjQuery很好,但它需要jQuery:)。仍然无效,因为您需要在#fieldid周围加引号。谢谢,我使用了隐藏字段和javascript组合,效果非常好。谢谢。我很高兴这对你有帮助。如果您喜欢,请标记为答案。谢谢,我使用了隐藏字段和javascript组合,效果非常好。谢谢。我很高兴这对你有帮助。如果你愿意,请把答案标出来。