1

ul 要素を使用してオートコンプリートを行う Web サイトがあります (JQueryMobile を使用)。初めてページをロードするときに、テキストを ul 入力 (data-role listview を使用した ul) に入力すると、db に保存されます。次に、別のサイトにリダイレクトしますが、再度同じ Web にアクセスすると、ul 入力で入力したデータがまだ残っています。そして、それをdbに送信するとエラーが表示されます(送信する前にフィールドを空にする必要があるため、エラーが発生します)。

Web を再充電するときに ul フィールドを空にするにはどうすればよいですか? で試しました

$("ul").html(" "); //not work
$("#id_div").remove(); //destroy the web and I can't enter again
$("#id_div").empty(); //same as above

私の悪い英語をありがとう、そしてごめんなさい!

編集:

私はさまざまな機能を持っています:

$( document ).on( "pageinit", "#confirm", function() {

    if(typeof localStorage.emails === 'undefined' || localStorage.emails === null){
        var mail = [];
        localStorage.emails = JSON.stringify(mail);
    }


    $( "#confirm_email1" ).on( "listviewbeforefilter", function ( e, data ) {
        var $ul = $( this ),
        $input = $( data.input ),
        value = $input.val(),
        html = "";
        $ul.html( "" );
        if ( value && value.length > 1 ) {

            var emails = JSON.parse(localStorage.emails)
            for(var i=0;i < emails.length;i++){
                html += "<li>" + emails[i] + "</li>";
            }
            $ul.html( html );
            $ul.listview( "refresh" );
            $ul.trigger( "updatelayout");
            $('li').click(function(){
                var mail = $(this).text();
                $input.val(mail);
                $ul.html( "" );
                $ul.listview( "refresh" );
                save_email1="";
                enviar_email1=mail;
            });

            save_email1 = $input.val();
            enviar_email1 = save_email1;
        }
    });

この関数を使用して、localStorage を作成し、li 要素を動的にオートコンプリートに追加します。

次に、この別のものを使用します。

function enviarReserva(){

    if(save_email1!==""){
        var emails = JSON.parse(localStorage.emails);
        emails.push(save_email1);
        localStorage.emails=JSON.stringify(emails);
    }

    var horafi = parseInt(horaReserva)+1;

    var check_soci1;

    if((enviar_email1!='' ) && (document.getElementById("soci_nosoci1").checked!=true)){
        check_soci1="no";
    }else{
        check_soci1="yeh";
    }

    $.ajax ( {
        beforeSend: function() { $.mobile.showPageLoadingMsg(); }, //Show spinner
        complete: function() { $.mobile.hidePageLoadingMsg() }, //Hide spinner
        url: "someURL?email1="+enviar_email1+"&check1="+check_soci1,
        dataType: "json",
        success: function (data, textStatus, jqXHR) {
            alert(data);
            actualitzarReserves();
            $.mobile.changePage("#mon",{transition:'none'});
            pag = 0;
            $('.pagina').html(pag);
            chargeWallet();
        },
        error: function (data, textStatus, jqHXR) {
            window.location.href="index.html";
        }
    });
}

この関数は、ul が空かどうか、およびチェックが選択されているかどうかをチェックします。次に、PHP は、check_soci が no の場合は何かを返し、check_soci が yeh の場合は別の値を返します。

私の問題は、同じ Web に 2 回目に入るときに、デフォルトで ul が空ではなく、PHP に送信される入力を空にしても、check_soci が no であることです。エラー!!

4

0 に答える 0