+ -
当前位置:首页 → 问答吧 → 关于form的action问题

关于form的action问题

时间:2010-02-01

来源:互联网

HTML代码:
复制代码
  1. <span id="Tip"></span>
  2. <form id="myForm" name="myForm" action="comment.php" method="post">
  3. <input type="text" size="50" name="names" id="names" /><br /><br />
  4. <textarea name="contents" id="contents" rows="10" cols="60"></textarea><br /><br />
  5. <input type="button" id="button" name="button" value="Submit Comment" onclick="doPost(this.form)" />
  6. </form>


Javascript:
复制代码
  1. function doPost(theForm) {
  2.  var sURL = $('#'+theForm.id).attr('action');
  3.  var options = {
  4.   url: sURL, //提交给哪个执行
  5.   type: 'POST',
  6.   error: function() {alert(sURL);},
  7.   success: function(msg){
  8.    $('#Tip').show();
  9.    $('#Tip').html(msg);
  10.   }
  11.  };
  12.  $('#'+theForm.id).ajaxSubmit(options);
  13.  return false;


为什么提交失败?好像sURL不正确啊。。。请帮忙看一下!

作者: goaler   发布时间: 2010-02-01

onclick="doPost($('#myform'))"

作者: ywqbestever   发布时间: 2010-02-01

囧,你的代码真乱,很多jQuery的细节并不了解

绑定事件不需要写onclick,直接用$('#button').click就能绑定了

而ajaxSubmit这个方法并不存在,应该用$.ajax函数

最后,$('#'+theForm.id)这种写法也是没必要的,直接$(theForm)就行了

作者: keakon   发布时间: 2010-02-03

相关阅读 更多