js怎么指定form中POST提交的参数

DDRsun3 2015-11-08 01:09:00

就是submit的时候,我想指定post的数据,例如下面一个编辑的表单,如果修改了手机号的话,就只post手机号就行了,其它没修改过的话就不post提交了,要怎么做?
因为我后台PHP的$_POST接收到的ARRAY[]是所有(real_name,mobile,email,gonghao,depatment),我只想接收修改过的参数就好,麻烦各位帮忙看看了,谢谢

麻烦各位帮忙看看,谢谢了


<form method="post" target="saveframe">
<table width="100%" border="0">
<tr>
<th width="30%" align="right">登录名</th>
<td width="70%"> {if getd('id')}
{$data['login_name']}
{else}
<input type="text" name="login_name" check='require'/>
{/if} </td>
</tr>
<tr>
<th align="right">密码</th>
<td> {if getd('id')} <a onclick="javascript:$(this).hide();$(this).next().show();">重置密码</a>
<input style="display:none" type="text" name="password"/>
{else}
<input type="text" name="password" check='require' value="123456" />
{/if} </td>
</tr>
<tr>
<th align="right">真实姓名</th>
<td><input type="text" name="real_name" value="{$data['real_name']}" check='require'/></td>
</tr>
<tr>
<th align="right">手机</th>
<td><input type="text" name="mobile" value="{$data['mobile']}" check='mobile'/></td>
</tr>
<tr>
<th align="right">email</th>
<td><input type="text" name="email" value="{$data['email']}" check='email'/></td>
</tr>
<tr>
<th align="right">工号</th>
<td><input type="text" name="gonghao" value="{$data['gonghao']}" check='require'/></td>
</tr>
<tr>
<th align="right">部门</th>
<td>{html::select($departments,$data['department'],'name=department;str=require')} </td>
</tr>
<tr>
<td style="text-align:center"> </td>
<td>{html::button()}</td>
</tr>
</table>
</form>


$('form').submit(function(){
if(!isFormChanged(null,null)){
//alert('表单内容为空或未改变!');
return false;
}else{
if(c.length == 0) return true;
if(cansub == 0){
c.each(function(){
validate.check_lagel(this,checks);
})
}
if(validate.checking > 0){
cansub = 1;
setTimeout(function(){
$('form :submit').click();
},20);
return false;
}else{
cansub = 0;
var cansubmit = true;
for(var i in validate.error){
if (validate.error[i]){
cansubmit = false;
break;
}
}
return cansubmit;
}
}
})
...全文
3792 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2015-11-08
  • 打赏
  • 举报
回复
propertychange有兼容问题,可以这样改。

<script>
$(function() {
  var st = {};
  $('[type=text]').bind('input propertychange', function() {
    st[this.name] = this.value;
  });
  $('form').submit(function(){
    $.post(this.action, st, function(d) { alert(d) });
    return false;
  });
});
</script>
DDRsun3 2015-11-08
  • 打赏
  • 举报
回复
引用 4 楼 xuzuning 的回复:
上面的事件绑定有问题,改一下 完整的测试例 test.php
<?php
if($_POST) {
  print_r($_POST);
  exit;
}
?>
<script src=scripts/jquery-1.8.3.min.js></script>
<script>
$(function() {
  var st = {};
  $('[type=text]').bind('propertychange', function() {
    st[this.name] = this.value;
  });
  $('form').submit(function(){
    $.post(this.action, st, function(d) { alert(d) });
    return false;
  });
});
</script>
<form action='test.php'>
<input type=text name=a>
<input type=text name=b>
<input type=text name=c>
<input type=submit value=ok>
</form>
引用 4 楼 xuzuning 的回复:
上面的事件绑定有问题,改一下 完整的测试例 test.php
<?php
if($_POST) {
  print_r($_POST);
  exit;
}
?>
<script src=scripts/jquery-1.8.3.min.js></script>
<script>
$(function() {
  var st = {};
  $('[type=text]').bind('propertychange', function() {
    st[this.name] = this.value;
  });
  $('form').submit(function(){
    $.post(this.action, st, function(d) { alert(d) });
    return false;
  });
});
</script>
<form action='test.php'>
<input type=text name=a>
<input type=text name=b>
<input type=text name=c>
<input type=submit value=ok>
</form>
浏览器断点到 $('[type=text]').bind('propertychange', function() { st[this.name] = this.value; 没触发呢~~~百度下,是说propertychange只支持IE?或者是绑定方法不对?求解~~
xuzuning 2015-11-08
  • 打赏
  • 举报
回复
上面的事件绑定有问题,改一下
完整的测试例
test.php
<?php
if($_POST) {
print_r($_POST);
exit;
}
?>
<script src=scripts/jquery-1.8.3.min.js></script>
<script>
$(function() {
var st = {};
$('[type=text]').bind('propertychange', function() {
st[this.name] = this.value;
});
$('form').submit(function(){
$.post(this.action, st, function(d) { alert(d) });
return false;
});
});
</script>
<form action='test.php'>
<input type=text name=a>
<input type=text name=b>
<input type=text name=c>
<input type=submit value=ok>
</form>
xuzuning 2015-11-08
  • 打赏
  • 举报
回复
var st = {};
$('[type=text]').propertychange(function() {
st[this.name] = this.value;
});
$('form').submit(function(){
$.post(this.action), st);
return false;
});

DDRsun3 2015-11-08
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
在文本框的 onpropertychange 事件中记录下控件的名字,供提交时使用 由于不知道你使用的是什么框架,所以就不写具体代码了
没有用什么框架,是自己写的一个仿smarty模版,和普通的juery美化表单,或者可以给相似的例子么?谢谢
xuzuning 2015-11-08
  • 打赏
  • 举报
回复
在文本框的 onpropertychange 事件中记录下控件的名字,供提交时使用

由于不知道你使用的是什么框架,所以就不写具体代码了

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧