我在SOF中检查了这个问题, How to prevent form element from sending some fields we don't want?
这是我的代码
的index.php
<script type="text/javascript">
$(formElement).submit(function() {
... how to do the jquery stuff..
return true;
});
<?php
$my_variable_with_value1 = 'abc';
$my_variable_with_value2 = 'def';
$another_one_variable = 'mango';
?>
<form method="post" action="process.php">
<input type="text" id="id1" name="name1" value="<?php echo $my_variable_with_value1 ?>" />
<input type="text" id="id2" name="name2" value="<?php echo $my_variable_with_value2 ?>" />
<input type="submit" value="Submit" />
</form>
我需要做以下事情 1.在提交页面之前,我需要仅使用JQUERY取消设置/清空变量值 2.我必须在index.php中显示变量,而不是在下一页中显示process.php
换句话说,我如何清空变量$ my_variable_with_value1 AND $ another_one_variable在页面提交之前使用JQUERY
谢谢, Kimz
答案 0 :(得分:0)
而不是使用
直接提交表单$(formElement).submit(function() {
在按钮中调用onclick
函数:
<input type="submit" value="Submit" onclick="submitform()" />
并且在js函数中,您可以将输入字段的值设置为空,如:
function submitform()
{
$('#id1').val('');
$('form').submit();
}
答案 1 :(得分:0)
使用以下代码,您可以将var1(ID)和var2(ID)的值设置为空白。
<script type="text/javascript">
$(formElement).submit(function() {
$("#Var1").val("");
$("#Var2").val("");
return true;
});