iframe頁面修改parent頁面的隱藏input部件value值,不能觸發change事件。
來源:程序員人生 發布時間:2014-11-20 08:09:13 閱讀次數:2893次
實現1個根據iframe頁面返回充值卡類型不同,安排不同的input部件。
點擊選擇彈出1個iframe,點擊充值卡數據行,返回1、充值卡類型。2、充值卡id(用的UUID)。3、充值卡號(字符串)。
遇到的問題是當iframe選擇充值卡時,沒法獲得parent頁面input部件value值的change事件。
parent頁js
$("#id_card_type").change(function(){
//事件沒法捕獲
});
parent頁form
<form id="frm" method="post" action="/bill/recharge/new/">
<input id="id_card_type" name="card_type" type="hidden" />
<input id="id_card_id" name="card_id" type="hidden" />
<label>卡號</label><input id="id_cardno" name="cardno" readonly="True" type="text" />
<span id="btnSelectCard" >選擇</span>
</form>
iframe頁js
$(this).children().click(function(){
<span style="white-space:pre"> </span>var cid=$(this).parent('tr').attr('item_id');
var cn=$(this).parent('tr').children('td').eq(0).html();
var ct=$(this).parent('tr').attr('item_type');
$('#id_card_id', window.parent.document).val(cid);
$('#id_cardno', window.parent.document).val(cn);
$('#id_card_type', window.parent.document).val(ct);
});
解決以下:
iframe頁js
$(this).children().click(function(){
var cid=$(this).parent('tr').attr('item_id');
var cn=$(this).parent('tr').children('td').eq(0).html();
var ct=$(this).parent('tr').attr('item_type');
$('#id_card_id', window.parent.document).val(cid);
$('#id_cardno', window.parent.document).val(cn);
$('#id_card_type', window.parent.document).val(ct);
//$('#id_card_type', window.parent.document).trigger('change'); //無效
window.parent.$('#id_card_type').trigger('change'); //有效
});
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈