我正在生成一个报告,我还需要输入值的html表单。我将表单(页面的HTML)保存,并将表单的输入保存到变量中。但是当我保存它时,输入不会进入它。
如何将值保存到其中?
HTML:
<form method="POST" action="<?php echo BASE_URL . 'php/processing/formInput/formDataInputProcesing.php?id=' . $_GET['id']; ?>" >
<div id="formHtml">
<?php echo $formHtml; ?>
<hr>
</div>
<input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" >
<div class="text-center">
<button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button>
</div>
<hr>
</form>
Javascript / JQuery:
<script type="text/javascript">
$('#submitData').click(function(){
var html = $('#formHtml').html();
$('#formHtmlValue').val(html);
});
</script>
答案 0 :(得分:0)
我正在使用旧方法
<form method="POST" onsubmit="setValue(this)" action="<?php echo BASE_URL . 'php/processing/formInput/formDataInputProcesing.php?id=' . $_GET['id']; ?>" >
<div id="formHtml">
<?php echo $formHtml; ?>
<hr>
</div>
<input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" >
<div class="text-center">
<button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button>
</div>
<hr>
</form>
<script language=javascript>
function setValue(v)
{
var tableContent=document.getElementById("formHtml").innerHTML;
v.formHtmlValue.value=tableContent;
return true;
}
</script>
答案 1 :(得分:0)
这是另一个例子:
<html>
<script src="https://code.jquery.com/jquery-git2.min.js"></script>
<body>
<form method="POST" action="abc.php?id=123" onsubmit="setValue()" >
<div id="formHtml">
<table>
<tr>
<td>
<input type=text name="t1"><span id="t1Value"></span>
<input type=radio name="r1" value="r1" checked><span id="r1Value"></span>
<input type=checkbox name="c1" value="c1" checked><span id="c1Value"></span>
</td>
</tr>
</table>
<hr>
</div>
<input type="hidden" value="" id="formHtmlValue" name="hiddenvalue" >
<div class="text-center">
<button type="submit" class="btn btn-info" name="submitData" id="submitData"><i class="fa fa-check">Submit</button>
</div>
<hr>
</form>
<script language=javascript>
function setValue()
{
var formHtml=$("#formHtml");
$("#formHtml input").each(function()
{
//console.log($(this).attr("name")+","+$(this).val());
itemName="#"+$(this).attr("name")+"Value";
$(itemName).html($(this).val());
$(this).remove();
});
$("#formHtmlValue").val($("#formHtml").html());
}
</script>
</body>
</html>