0

ページの読み込み時に jquery を実行しようとしていますが、現在は機能しています。リンクが既に保存されているかどうかを確認し、保存されている場合はテーブルをそれに設定します。img クラスを持つすべての div に対して実行する必要があるため、これは可能ですか?

$(document).ready(function(){
    $(".img a").live('pageshow', function(event, ui) {
        var item=$(this).attr( 'href' );
        var action="check";
        jqxhr = $.post("webservice.php", { action: action, color: item }, function(data) {
            var result=data.result;
            if (result="saved") {
                $("span", this).html("Saved");
                $(this).attr("href","saved");
            }

        }, "json")
        .error(function() {         
            alert("error: unable to contact web service"); 
        });
    });
});

ここにHTMLがあります

                            <td>
                                <div class="img" style="background:#f8d3cf;">
                                    <a href="f8d3cf" rev="1" class="link">
                                        <span>Click to Save</span>
                                        <em>Saved</em>
                                    </a>
                                    <div class="popup">
                                        <div class="holder">
                                            <div class="popup-img" style="background:#f8d3cf;"></div>
                                            <div class="info">
                                                <h3>Desert Warmth</h3>
                                                <strong class="num">70YR 56/190 <span>A0542</span></strong>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </td>
4

2 に答える 2

0

前述のように、pageshow は qmobile イベントであり、onpageshow はすべてのブラウザーでサポートされていない html5 です。答えは、「window.onload= function() {};」を使用することです。その window.onload 内のすべてが、ページの読み込み時に処理されます。これがwindow.onloadの使用方法です。最初の ajax 呼び出しは、セッションから cart_id をロードするか、必要に応じて作成します。ajax 呼び出しが完了すると、ショッピング カートに商品を入れるアプリケーションが呼び出されます。

window.onload = function() {
    $j(".cartid").each(function() {
        var self = $j(this);

        jqxhr = $j.post("mycartid.php", function(data) {
            self.html(data.cart_id);
        }, "json").complete(function() {

            $j("#cartitems").each(function() {
                var self = $j(this);
                jqxhr = $j.post("printitems.php", function(data) {
                    //var result=data.result;
                    self.html(data);
                }, "html");

            });
        });
    });
 };
于 2012-11-08T12:10:10.763 に答える
0

あなたの最後の行に '));' '}); である必要があります。

$(document).ready(function(){
    $(".img a").live('pageshow', function(event, ui) {
        var item=$(this).attr( 'href' );
        var action="check";
        jqxhr = $.post("webservice.php", { action: action, color: item }, function(data) {
            var result=data.result;
            if (result="saved") {
                $("span", this).html("Saved");
                $(this).attr("href","saved");
            }

        }, "json")
        .error(function() {         
            alert("error: unable to contact web service"); 
        });
    });
});
于 2012-11-08T12:14:04.043 に答える