iframe頁(yè)面修改parent頁(yè)面的隱藏input部件value值,不能觸發(fā)change事件。
來(lái)源:程序員人生 發(fā)布時(shí)間:2014-11-20 08:09:13 閱讀次數(shù):2898次
實(shí)現(xiàn)1個(gè)根據(jù)iframe頁(yè)面返回充值卡類(lèi)型不同,安排不同的input部件。
點(diǎn)擊選擇彈出1個(gè)iframe,點(diǎn)擊充值卡數(shù)據(jù)行,返回1、充值卡類(lèi)型。2、充值卡id(用的UUID)。3、充值卡號(hào)(字符串)。
遇到的問(wèn)題是當(dāng)iframe選擇充值卡時(shí),沒(méi)法獲得parent頁(yè)面input部件value值的change事件。
parent頁(yè)js
$("#id_card_type").change(function(){
//事件沒(méi)法捕獲
});
parent頁(yè)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>卡號(hào)</label><input id="id_cardno" name="cardno" readonly="True" type="text" />
<span id="btnSelectCard" >選擇</span>
</form>
iframe頁(yè)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頁(yè)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'); //無(wú)效
window.parent.$('#id_card_type').trigger('change'); //有效
});
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)