休息時間寫一篇.....(好像休息很久了)

今天遇到客戶的一個問題是為什麼商品加不進去購物車(他用 IE6)

這年代是要去哪裡找 IE6,IE6 是 windows 2000 時代的東西

實在是很想忽略不管.....但還是很不爭氣的找了問題....

 

然後我是這樣寫的

html : 

<a href="javascript:{void(0)}" id="gobasket"><img src="......."></a>

<asp:DropDownList ID="Spec" runat="server" AppendDataBoundItems="True">

.............

</asp:DropDownList>

 

script : 

$("#gobasket").click(function(){

    if($("#Spec").val() == "0") {

         alert('請先選擇規格!');

         $("#Spec").focus();

    } else {

         $("#prodno").val($("#Prodnox").html() + '@' + $("#Spec").val());

         $("#proddata").submit();

    }

});

 

 

光上面這段簡單的 script ,IE6 就有2個問題真不簡單

1. jQuery 下拉選單在 IE6 不能用 .val() 取值

    所以....請老老實實的用以前的 document.getElementById 抓

    然後保險起見 html 記得再加個 name,ex : <select name="test" id="test"

    因為印象中之前的 IE6 用 getElementById 會抓到 name (冏)

    這 bug 雖然已經修正了,但舉手之勞還是加一下 name

2. 如果有 form 要 submit(),  click 的主體必需要用 #,不能用 void(0)

    ex: 我上面寫的 <a href="javascript:{void(0)}" id="gobasket">  <----死

    還有如果是用 location.href='...........',很抱歉也會失效,請改成 #

    但這解決方式真的很莫名奇妙.....改成 # 一開始會跳到頁面上方

    但是總比沒解決好.... 

 

所以最後 script  改成

 

html : 

<a href="#" id="gobasket"><img src="......."></a>

<asp:DropDownList ID="Spec" runat="server" AppendDataBoundItems="True">

.............

</asp:DropDownList>

 

script : 

$("#gobasket").click(function(){

    if(document.getElementById('Spec').value == "0") {

         alert('請先選擇規格!');

         $("#Spec").focus();

    } else {

         $("#prodno").val($("#Prodnox").html() + '@' + document.getElementById('Spec').value);

         $("#proddata").submit();

    }

});

 

3774283814_c5f71db141.jpg  

arrow
arrow
    全站熱搜

    小雕 發表在 痞客邦 留言(0) 人氣()