請問一個js的寫法 在firefox沒問題 IE8上卻會出錯
[i=s] 本帖最後由 alucardc 於 2012-9-5 09:44 編輯 [/i]首先要先說明一下我對javascript與jQuery都是非常非常*n新手 只是copy公司前輩的程式碼來用
所以先說明一下這些程式碼的目的
[color=Blue]目的[/color] : 在html做出來的一個下拉式選單裡 若是選中了其中一個選項 (信用卡)
此時畫面中會跑出信用卡卡號、有效日期等等的 input 欄位
若是選了別的選項,這些欄位則不會顯示出來,程式碼如下
[color=Red]html部分
/////////////////////////////////////////////////////////////////////[/color]
<span id='credit'>
信用卡號:
<input type='text' name='credid' id='credid' value='<?=$credid?>' size='20' maxlength='19' /></br>
信用卡有效日期:
<select id='expiry_year' name='expiry_year' onchange='update_expiry()'><?=select_expiry_year();?></select>年
<select id='expiry_mon' name='expiry_mon' onchange='update_expiry()'>
<?=select_expiry_mon()?></select>月
</span>
[color=Red]javascript部分
/////////////////////////////////////////////////////////////////////[/color]
<script type='text/javascript'>
function show_credit(obj){
credit = document.getElementById('credit');
if(obj.value == '信用卡'){
credit.style.display = 'inline';
}
else{
credit.style.display = 'none';
}
}
var tooltip = new Array();
$(document).ready(show_credit(document.getElementById('billac_type')));
jQuery(function($){
$("#credid").mask("9999-9999-9999-9999",{completed:function(){alert("信用卡號格式不符: "+this.val());}});
$("#credit_date").mask("99/99",{completed:function(){alert("信用卡有效日期不符: "+this.val());}}) ;
});
</script>
[color=Red]/////////////////////////////////////////////////////////////////////[/color]
IE8 左下角 錯誤三角型 出現的錯誤訊息是
網頁錯誤詳細資料
使用者代理程式: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
時間戳記: Wed, 5 Sep 2012 01:24:13 UTC
訊息: 物件不支援此屬性或方法
行: 361
字元: 4
程式碼: 0
URI: http://localhost/WEBERP/000werp/store/index.php?act=shopcar
然後361行 就是
[color=Blue]credit = document.getElementById('credit');[/color]
這邊
不知道該怎麼修正這個錯誤?
又或者是有另外可以達成同樣目的的程式寫法,有範例可以給我參考
謝謝各位 [b]回復 [url=http://jsgears.com/redirect.php?goto=findpost&pid=3425&ptid=2108]1#[/url] [i]alucardc[/i] [/b]
應該是變數名稱產生的衝突,你有一個變數叫 credit,另外頁面上有個 id credit 的元素,可能在 IE 造成了問題,先試試看把變數名稱改掉。
頁:
[1]