gpt4 book ai didi

javascript - 使用提交按钮提交表单时如何将javascript变量发送到php中的另一个页面

转载 作者:行者123 更新时间:2023-11-27 23:28:23 26 4
gpt4 key购买 nike

我在 JavaScript 中有两个变量,col1 和 col2,当单击提交按钮时,我需要将它们发送到 PHP 页面。

我有以下代码:

<script>
$("input:radio").change(function(){
if($(this).is(":checked")){
var col1 = $(this).parent().parent().children("td:first");
var col2 = col1.next();
}
})
</script>

最佳答案

使用表单中的隐藏元素并为其赋值。

HTML

<form>
<!--other code-->
<input type="hidden" id="col1" name="col1">
<input type="hidden" id="col2" name="col2">
</form>

JQUERY

$("input:radio").change(function(){
var col1 = '', col2 = '';
if($(this).is(":checked")){
col1= $(this).parent().parent().children("td:first");
col2 = col1.next();
}
$('#col1').val(col1);
$('#col2').val(col2);
});

关于javascript - 使用提交按钮提交表单时如何将javascript变量发送到php中的另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34767106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com