[英]jQuery append after submitting with colorbox iframe
如果您可以通過以下代碼幫助我。 由於某種原因, 它不會在提交#appendAffiliate
立即將行追加到表#appendAffiliate
。 我使用colorbox作為模式對話框。
注意:只有在以色箱模式提交表單時才會發生這種情況。
HTML:
<a href="page/frame.php" class="colorbox-iframe"></a>
frame.php FILE (modal):
<form>....</form>
table markup:
<table width="100%" id="appendAffiliate">
<thead>
<tr>
<th>Name</th>
<th>Discount</th>
</tr>
</thead>
<tbody></tbody>
</table>
JAVASCRIPT:
$('.colorbox-iframe').colorbox({
overlayClose: false,
iframe: true,
scrolling: false,
innerWidth: 200,
innerHeight:150
});
$('form').submit(function(){
$.ajax({
type: 'post',
url: 'json/json.php',
data: $(this).serialize(),
dataType: 'json',
cache: false,
success: function(data) {
if ( data.ok ) {
// None working
$('#appendAffiliate').append('<tr><td>test</td><td>test</td></tr>');
$('#appendAffiliate > tbody').append('<tr><td>test</td><td>test</td></tr>');
$('#appendAffiliate tbody:last').append('<tr><td>test</td><td>test</td></tr>');
$('input[type="submit"]').prop('disabled',true);
setTimeout(function(){
$('input[type="submit"]').prop('disabled',false);
**parent.$.fn.colorbox.close();**
},2000);
} else {
}
}
});
return false;
})
您應該附加到thead
碼
$('#appendAffiliate thead').append('<tr><td>test</td><td>test</td></tr>');
您的帖子沒有明確區分父窗體(調用ColorBox的頁面)中的標記/ js和ColorBox顯示的內容中的標記/ js。
如果該表位於父級中,則在進行追加時一定要引用父級。 (您可能試圖在子頁面中追加一個可能不存在的節點。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.