我正在尝试将 javascript 变量传递到表单字段并将结果作为 url 变量发送,但我坚持使用此代码。任何帮助表示赞赏。代码将浏览器宽度视口输出到字段字段中,然后在提交表单时将其作为变量发送到 url
<html>
<script>
function getViewport() {
var viewPortWidth;
var viewPortHeight;
window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined') {
viewPortWidth = window.innerWidth,
viewPortHeight = window.innerHeight
}
return viewPortWidth;
}
</script>
<form action ='echo.php' method = 'GET'>
<table>
<tr>
<td>
<input type='hidden' name='r_w' onsubmit='this.value=getViewport();'>
<td>
<td>
<input type="submit" name='submit' value="Go" />
</td>
</tr>
</table>
</form>
</html>