JQuery .submit 函数不会在 IE 中提交表单

发布于 2024-08-29 01:52:56 字数 1432 浏览 6 评论 0 原文

我有一个表单,它向 JQuery 代码提交一些值,然后该代码发送一封包含表单中的值的电子邮件。它在 Firefox 中完美运行,但在 IE6(惊讶!)或 IE7 中不起作用。有人有什么建议吗?非常感谢?我在一些博客上看到它可能与我表单中的提交按钮有关,但我尝试过的似乎都不起作用。

这是表单 html:

<form id="myform1">

<input type="hidden" name="itempoints" id="itempoints" value="200"> </input>

<input type="hidden" name="itemname" id="itemname" value="testaccount"> </input>

<div class="username">
    Nickname:

    <input name="nickname" type="text" id="nickname" />
</div>
<div class="email">
    Email:
    <input name="email" type="text" id="email" />
</div>
<div class="submitit">
    <input type="submit" value="Submit" class="submit" id="submit" />
</div>

</form>

这是我的 JQuery:

var $j = jQuery;

$j("form[id^='myForm']").submit(function(event) {

 var nickname = this.nickname.value;
 var itempoints = this.itempoints.value;
 var itemname = this.itemname.value;
 event.preventDefault();  
 var email = this.email.value;
 var resp = $j.ajax({
  type:'post',
  url:'/common/mail/application.aspx',
  async: true,
  data: 'email=' +email 
   + '&nickname=' + nickname 
   + '&itempoints=' + itempoints 
   + '&itemname=' + itemname,
  success: function(data, textStatus, XMLHttpRequest) {
   alert("Your mail has been sent!");
   window.closepopup();

  }
 }).responseText;
 return false;
});

I have a form that submits some values to JQuery code,which then which sends off an email with the values from the form.It works perfectly in Firefox, but does not work in IE6(surprise!) or IE7. Has anyone any suggestions why? greatly appreciated?I saw on some blogs that it may have something to do with the submit button in my form but nothing Ive tried seems to work.

Here is the form html:

<form id="myform1">

<input type="hidden" name="itempoints" id="itempoints" value="200"> </input>

<input type="hidden" name="itemname" id="itemname" value="testaccount"> </input>

<div class="username">
    Nickname:

    <input name="nickname" type="text" id="nickname" />
</div>
<div class="email">
    Email:
    <input name="email" type="text" id="email" />
</div>
<div class="submitit">
    <input type="submit" value="Submit" class="submit" id="submit" />
</div>

</form>

and here is my JQuery:

var $j = jQuery;

$j("form[id^='myForm']").submit(function(event) {

 var nickname = this.nickname.value;
 var itempoints = this.itempoints.value;
 var itemname = this.itemname.value;
 event.preventDefault();  
 var email = this.email.value;
 var resp = $j.ajax({
  type:'post',
  url:'/common/mail/application.aspx',
  async: true,
  data: 'email=' +email 
   + '&nickname=' + nickname 
   + '&itempoints=' + itempoints 
   + '&itemname=' + itemname,
  success: function(data, textStatus, XMLHttpRequest) {
   alert("Your mail has been sent!");
   window.closepopup();

  }
 }).responseText;
 return false;
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半寸时光 2024-09-05 01:52:56

您的 jQuery 选择器正在寻找 myForm,但表单的 id 是 myForm1

$j("form[id^='myForm']") 与表单 id="myform1

尝试 $j('form#myform1')...

Your jQuery selector is looking for myForm, but the form's id is myForm1

$j("form[id^='myForm']") vs. form id="myform1"

Try $j('form#myform1')...

木格 2024-09-05 01:52:56

看起来您的表单需要一个方法操作

Looks like your form needs a method and action.

悲歌长辞 2024-09-05 01:52:56

既然您实际上并未提交表单,为什么不将提交按钮设置为按钮而不是提交并在 click event() 中执行以下操作,如下所示:

var $j = jQuery;

$j("#btnSubmit").click(function(event) {

 var nickname = $("#nickname").val();
 var itempoints = $("#itempoints").val();
 var itemname = $("#itemname").val();

 var email = this.email.value;
 var resp = $j.ajax({
  type:'post',
  url:'/common/mail/application.aspx',
  async: true,
  data: 'email=' +email 
   + '&nickname=' + nickname 
   + '&itempoints=' + itempoints 
   + '&itemname=' + itemname,
  success: function(data, textStatus, XMLHttpRequest) {
   alert("Your mail has been sent!");
   window.closepopup();

  }
 })
});

HTH

Since you are not actually submitting the form why don't you just make the submit button as a button instead of submit and do the stuff in click event() as shown below:

var $j = jQuery;

$j("#btnSubmit").click(function(event) {

 var nickname = $("#nickname").val();
 var itempoints = $("#itempoints").val();
 var itemname = $("#itemname").val();

 var email = this.email.value;
 var resp = $j.ajax({
  type:'post',
  url:'/common/mail/application.aspx',
  async: true,
  data: 'email=' +email 
   + '&nickname=' + nickname 
   + '&itempoints=' + itempoints 
   + '&itemname=' + itemname,
  success: function(data, textStatus, XMLHttpRequest) {
   alert("Your mail has been sent!");
   window.closepopup();

  }
 })
});

HTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文