0
我有一個父頁面需要由iframe調用的函數,然後這個函數更新iframe中的表單值。我可以調用的功能正常,但表格值更新不起作用從iframe調用父功能,然後更新iframe的形式值
我設置了一個警報,看父函數是否可以看到輸入值,但返回undefined,所以我假設我沒有正確訪問ID的
這裏是我的代碼試圖自動初始化今天的領域日期分成三個文本框
主要js函數
window.autoPartialDateBox = function(htmlID) {
if (!jQuery('#'+htmlID+"_mm").val() && !jQuery('#'+htmlID+"_dd").val() && !jQuery('#'+htmlID+"_yy").val()) {
var myDate = new Date();
jQuery('#'+htmlID+"_mm").val(myDate.getMonth()+1);
jQuery('#'+htmlID+"_dd").val(myDate.getDate());
jQuery('#'+htmlID+"_yy").val(myDate.getFullYear());
} }
IFRAME
<script type="text/javascript">
$(function() {
// this will populate the partial date box
$("#someElement").live("change", function() {
if ($(this).val() == 'trigger') {
window.top.autoPartialDateBox('partial_date_box');
}
});
});
</script>
Action <select name="someElement" id="someElement" class="valid">
<option value="" selected="">Select an option</option>
<option value="trigger">Trigger</option>
</select>
Day <input name="stop_dd_2747_mm" type="text" id="stop_dd_2747_mm">
Month <input name="stop_dd_2747_dd" type="text" id="stop_dd_2747_dd" >
Year <input name="stop_dd_2747_yy" type="text" id="stop_dd_2747_yy" >
相同的錯誤,不能調用的未定義的方法 'VAL'。在函數被包含在文檔中時,在jquery選擇器中構建一個字符串可以正常工作,當它包含在頂部/父項中時失敗,然後嘗試調用 – 2012-07-18 18:18:25
如果錯誤發生在If上,那麼您需要檢查'.val )'爲每個子節點。 '!node [0] .val()'等等。如果錯誤發生在node [0] .val()上,那麼該節點需要用'$'在jQuery名稱空間中聲明。 – ExceptionLimeCat 2012-07-18 18:29:55
我編輯了IF&'節點'聲明。 – ExceptionLimeCat 2012-07-18 18:33:19