我在 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/