$ this.attr()从打开开始停止Jquery对话框

时间:2010-06-05 11:36:50

标签: jquery ajax forms post dialog

我使用以下代码将表单数据发布到player / index.php并在对话框中打开它。因为我的表中有多个这些表单,所以我需要使用$(this)。

但现在它没有在对话框中打开。

新代码(不打开对话框,但在网址中显示数据):

  $("#recordingdialog").dialog({
  //other options, width, height, etc...
     modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 200,
      width: 350,
      draggable: true,
      resizeable: true,
      title: "Play Recording",});

$(this).click(function() {
  $.post('player/index.php', $(this).attr('form').serialize(), function (data) {
       $("#recordingdialog").html(data).dialog("open");
  });
  return false;
});

旧代码(仅适用于一种形式):

      $("#recordingdialog").dialog({
  //other options, width, height, etc...
     modal: true,
      bgiframe: true,
      autoOpen: false,
      height: 550,
      width: 550,
      draggable: true,
      resizeable: true,
      title: "Play Recording",});


$("#wavajax button").click(function() {
  $.post('player/index.php', $("#wavajax").serialize(), function (data) {
       $("#recordingdialog").html(data).dialog("open");
  });
  return false;
});

2 个答案:

答案 0 :(得分:1)

而不是.attr()您想要的是.closest(),如下所示:

$(this).click(function() {
  $.post('player/index.php', $(this).closest('form').serialize(), function (data) {
       $("#recordingdialog").html(data).dialog("open");
  });
  return false;
});

这会得到最近的父元素<form> ...所以你当前所在的<form> :)而不是$(this)作为{{1}的选择器我你是指任何这些按钮,如果是这样的话给他们一个像click这样的类并使用那个选择器,就像这样:

<button class="dialogBtn">

答案 1 :(得分:0)

您应该查看控制台输出中的错误。

 $(this).attr('form')

将返回一个字符串,您不能在字符串上使用.serialize()

您还在什么情况下执行代码?在您拥有选择器之前,现在您只使用this

相关问题