2012-05-30 127 views
2

我的php脚本中有两个函数放在QandA2Table.php中,但是它们的按钮放在previousquestions.php页面中,因为模态窗口显示该页面的详细信息。模态窗口不关闭

反正我有两个按钮,下面是一个“关闭”按钮和“添加”按钮:

<div id="previouslink"> 
<button type="button" id="close" onclick="return parent.closewindow();">Close</button> 

</div> 

<?php 

     $output = ""; 

     while ($questionrow = mysql_fetch_assoc($questionresult)) { 
$output .= " 
<table> 
     <tr> 
     <td id='addtd'><button type='button' class='add'>Add</button></td> 
     </tr>"; 
     } 
     $output .= "  </table>"; 

     echo $output; 

    } 

} 

?> 

我的问题是关闭模式窗口。当我点击“关闭”按钮时,它关闭了很棒的模式窗口,但是如果我点击一个“添加”按钮,它就不会关闭模态窗口。为什么是这样?

下面是两个按钮的功能:

function closewindow() {  

    $.modal.close(); 
    return false; 
} 

     $(".add").on("click", function(event) { 
     console.log("clicked"); 

     var theQuestion = $("td:first-child", $(this).parent()).text(); 

     if ($('.activePlusRow').length > 0) { 
      $('.activePlusRow').next('.textAreaQuestion').val(theQuestion); 
     } 
     parent.closewindow(); 
     return true; 
    }); 

下面是IFRAME:

function plusbutton() { 
    // Display an external page using an iframe 
    var src = "previousquestions.php"; 
    $.modal('<iframe src="' + src + '" style="border:0;width:100%;height:100%;">'); 
    return false; 
} 
+0

欢迎添加ID的iframe中创建者线SO !在添加按钮处理程序中运行'$ .modal.close()'之前是否存在JavaScript错误? –

+0

@Jack没有错误显示在错误控制台 – user1394925

+0

'self.parent.tb_remove()'中,关闭iframe窗口。 – Rafee

回答

0

如果我没有得到你错了。原因和解决方案很简单

你的模态容器页面 - 你在里面创建iframe--有这些功能吗?

closewindow()和功能plusbutton()

他们身边还必须在主HTML

$(".add").on("click", function(event) { 
    ............... 

部分-event catcher-如果我的理解对不对?

所以你不能指望$(“添加‘)。在(’点击”,函数(事件)......通过iframe内的一个按钮来触发。

什么,你可以简单地做的是将$( “添加 ”)。在(“ 点击”,函数(事件)传递给函数

CHAGE是

$(".add").on("click", function(event) { 
    console.log("clicked"); 

    var theQuestion = $("td:first-child", $(this).parent()).text(); 

    if ($('.activePlusRow').length > 0) { 
     $('.activePlusRow').next('.textAreaQuestion').val(theQuestion); 
    } 
    parent.closewindow(); 
    return true; 
}); 

function add_function { 
    console.log("clicked"); 

//通过添加帧ID参考来更改此部分以适合您的内容层次。 //我不知道你会在td中解析的数据:first-childs parent。 var theQuestion = document.frames [“the_frame”]。$(“td:first-child”,$(this).parent())。text();

if ($('.activePlusRow').length > 0) { 
     $('.activePlusRow').next('.textAreaQuestion').val(theQuestion); 
    } 
    parent.closewindow(); 
    return true; 
} 

和更改iframe中的内容这一行

<td id='addtd'><button type='button' class='add'>Add</button></td> 

<td id='addtd'><button type='button' class='add' onclick="parent.add_function();" >Add</button></td> 

和在plusbutton功能

$.modal('<iframe if="the_frame" src="' + src + '" style="border:0;width:100%;height:100%;">');