我一直在嘗試從我的窗口模態子窗口傳遞任何值到父窗口,但它不起作用。 modal
不會hide
或當我單擊Save
時將值發送到父窗口。如何將價值從一個助推器模態孩子傳遞給父母?
application.php
<body>
<h3 class="h3 black">Application</h3>
<form class="form-horizontal" method="post" action="admin-controller.php" name="f1">
<input type="text" name="p_name" id="n1" >
<?php
include 'includes/calendar.php';
$calendar = new Calendar();
echo $calendar->show();
?>
</form>
</body>
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0 /jquery.validate.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript">
function post_value(){
window.opener.document.f1.p_name = document.myform.skill_id_t.value;
$('#modal_1').modal('hide');
}
</script>
calendar.php
<?php
class Calendar {
public function show() {
//some code
$html .=$this->_showDay($someValues);
//some code
}
private function _showDay($cellNumber){
// Build up the html.
$html = '<td id="' . $this->currentDate . '" class="td-top-text ' . $classNameOne . $classNameTwo . '">';
//Radio button that open the Modal window
$html .= '<input type="radio" data-toggle="modal" data-target="#modal_1" name="schedule_id" value="'. $shedule_id.'">';
//singleModal
$html .=$this->_singleModal();
$html .= '</td>';
return $html;
}
//child window
public function _singleModal(){
//Single Modal
$html = '<form name="myform" method="post" action="">';
$html .= '<div class="modal fade" id="modal_1" role="dialog">';//Modal open
$html .= '<div class="modal-dialog">';//Modal Dialog open
$html .= '<div class="modal-content">';//Modal-Content Open
$html .= '<div class="modal-header">';//Modal-Header open
$html .= '<button type="button" class="close" data-dismiss="modal">×</button>';//bbutton
$html .= '<h4 class="modal-title bold cyan">Sign Up (Single)</h4>';//Title H4
$html .= ' </div>';//Modal-header Close
$html .= '<div class="modal-body">';//Modal-body open
//Type something to pass to parent window
$html .= '<input name="skill_id_t" type="text">';
$html .= '</div>';//Modal-body close
$html .= '<div class="modal-footer">';//Footer open
$html .= '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';//button
$html .= '<input onclick="post_value();" id="save" type="button" name="save-details" value="Save">';//input
$html .= '</div>';//Footer Close
$html .= '</div>';//Modal-content close
$html .= '</div>';//Modal Dialog Close
$html .= '</div>';//Modal close
$html .= '</form>';
return $html;
}
}
我讀其他職位,據他們說,問題可能是因爲javascript
我不能使用data-target="#modal_1"
與javascript
如此我試圖刪除target
,並且只需將onclick
調用函數調入我的<input name="schedule_id">
要做$(#modal_1).modal('show');
但仍然$(#modal_1).modal('hide');
不起作用。
我也有標籤php
因爲根據其他職位,我需要將javascript
包括到我php
(calendar.php
),而不是在我的application.php
編輯 我也我點擊每一次得到了一些錯誤Save
TypeError: opener is null
試圖通過增加window.opener...
修復它,但它沒有工作,要麼
新編輯:
我不得不改變我的js
代碼這樣:
$(function() {
$('#btnLaunch_1').click(function() {
$('#modal_1').modal('show');
});
$('#btnSave_1').click(function() {
opener.document.f1.p_name = document.myform.skill_id_t.value;
$('#modal_1').modal('hide');
});
$('#cancel_1').click(function() {
$('#modal_1').modal('hide');
});
});
,我刪除必須與data-target
包括關閉窗口data-dismiss
之一的一切。而且,我意識到問題是這條線opener.document.f1.p_name = document.myform.skill_id_t.value;
由於某種原因,通過給出上述錯誤這條線路失敗。 ...opener is null
Pleaseeee helpp =/II我在這裏努力工作....
我想在POST_VALUE您可能需要將該值賦給* p_name.value *而不是* p_name *。 – AverageUnknown
@AverageUnknown感謝您的評論。我改變了,但仍然說'開啓者爲空' –
是否有你使用* window.opener.etc *而不是像* $('[name =「p_name」]')*之類的原因?我不熟悉你使用的語法。 – AverageUnknown