1

ショッピング カートのスクリプトにアクセントの問題があります。ここに私のJavascriptコードの一部があります:

//process product groups
        products.each(function(gid) {
            //create groups of products
            var gname = this.id.replace(/_/g, ' ');
            var gbutton = $('<a />',{'title':gname, 'prod_id':this.id,'href':'#'}).text(gname);
            $('<li/>').append(gbutton).appendTo(groups);

            //register onclick event for group link
            gbutton.click(function(e) {
                //make clicked group active
                groups.find('.active-group').removeClass('active-group');
                $(this).parent().addClass('active-group');
                //hide all groups 
                products.css('display','none');
                active_group = $('#' + $(this).attr('prod_id'), shop);
                //show only active group
                active_group.css({'top':0,'display':'block'});
                //animate products by shifting their top position and tweening opacity
                active_group.children('li').each(function(i){
                  $(this).css({'top':parseInt((i+settings.pageColumns)/settings.pageColumns)*settings.groupAnimationShift,'opacity':0});
                  $(this).delay(i*settings.groupAnimationStartDelay).
                  animate({'top':0,'opacity':1},settings.groupAnimationTime,settings.groupAnimationEasing);
                });
                //update number of pages
                active_group.current_page = 1;
                active_group.pages = Math.ceil(active_group.children('li').length / (settings.pageRows*settings.pageColumns));
                //update page scroll
                resetPageScroll();
                e.preventDefault();
            });

HTML 内の UL id とリンクされています。

元。:

<ul id="Enseignes_Résidentielles">

                  <li class="product" name="RD-101" price="5" minimum="4" skip="4"> 
                         <a class="product-image fancybox" href="images/product_big.jpg" title="Picture 4">
                             <img src="images/product_2.png" alt="Preview"/>
                             <div class="text-overlay">
                              <p class="product-heading">Description</p>
                               Enseignes résidentielles imprimées sur 2 panneaux 4 mm 36” x 24” collés dos à dos.
                             </div>
                         </a>
                         <p class="product-heading">RD-101 (Simple)</p>
                         <a href="#" id="test" class="product-buy">Ajouter au panier</a>
                         <p class="product-meta">Double de pareterre 32x24</p>
                         <div class="product-price">18<span class="product-currency">$</span></div>

                    </li>

UL ID にアクセントやその他の句読点を追加すると、ショッピング カート DIV のすべての関数を除いてすべてが機能します... UL ID にアクセントやその他の utf-8 文字が含まれていない場合、正常に機能します。

理由はありますか?そして、これを修正する方法はありますか?


編集

これがライブ プロジェクトです... : http://danalcoimpressions.com/remax/index.html これを試してください...最初のタブ (Enseignes Résidentielles) の任意の項目で [Ajouter au panier] をクリックします... ショッピング カートにカーソルを合わせますタブを開き、そのカテゴリから項目を追加または削除しようとしても機能しません。しかし、タブ (UL) 名にアクセントがない 2 番目のタブ (Enseignes Balcon) で同じことを試してみてください。ショッピング カートでうまく機能します。

4

2 に答える 2

3

from HTML の id 属性の有効な値は何ですか?

ID および NAME トークンは文字 ([A-Za-z]) で始まり、その後に任意の数の文字、数字 ([0-9])、ハイフン ("-")、アンダースコア ("_") が続く場合があります、コロン (":")、およびピリオド (".")。

于 2012-06-12T17:24:37.247 に答える
1

問題はこのコードにあると思います:

function itemRemoveHandler(p) {
  //look for item in cart
  var filter = /(\w+)::(\w+)/.exec(p.id);
  delete cart[filter[1]][filter[2]];

JavaScript は、正規表現での Unicode 文字のサポートがひどいものです。特に、\wオペレーターが正しく動作しません。したがって、一致が機能しないため、delete改行されます。

回避策として何を提案すればよいかわかりません。特殊文字を「id」値から除外するか、正規表現で作業することができます。

編集— OK 確認済み; 正規表現を文字列に適用すると、アクセント付きの文字と一致しません。

于 2012-06-12T18:06:02.287 に答える