我有一個函數,用於偵聽onkeyup事件,onkeyup檢查是否有一個框有一個值,如果不是空白,應該拉一個elementID的值,這是從另一個調用的電話號碼頁。它接受該值並將其插入到發送給另一個elementID的html代碼片段中。下面的代碼是功能和相關的代碼。加載,但使用Smarty模板是寫在單獨的頁面時document.getElementById是NULL錯誤
<script language="javascript">
function monthlycheck() {
var mnthchk = document.getElementById("mdamountBox");
var cancelPhone = document.getElementById("cancelphoneLabel");
document.getElementById("cancelphonelistLabel").value = cancelPhone; <--gives the is null error
if(mnthchk.value!=""){
var newHTML = "<span style='color:#24D330'> Your Monthly pledge in the amount of $__ is valid and will be deducted this time every month<br> untill you notify us of its cancellation by calling <label id='cancelphonelistLabel'> </label>";
" </span>";
document.getElementById("mnthlychkdiscoLabel").innerHTML = newHTML;
}
}
</script>
<label id="mnthlychkdiscoLabel"> </label> <---this is where the final data is to be displayed
<label id="cancelphoneLabel">1-800-555-1111</label> <--- this is the phone number pulled from another page,
所有的數據都在一個頁面拉到一起。我不斷收到有關錯誤,並嘗試了許多不同的事情來解決它,但即時通訊任何幫助非常感謝。
這裏是一個jfiddle http://jsfiddle.net/rn5HH/
另一頁?你可以訪問另一個頁面的元素? – 2013-05-13 21:43:14
你可以扔在小提琴嗎? – samayo 2013-05-13 21:44:30