0

私は、起動ページを実行する次のコードを持っています。これにより、繰り返しetape.htmlでhtmlブロックにhtml要素を挿入できます。n

最初の反復ではすべて問題なく表示されますが、2 回目の反復では div ブロックに何も表示されません。

二次的な考慮事項は、ページをリロードできる「 Suivant 」ボタンを押すと実行されますetape.html

誰かが何か考えがありますか?

index=0;    
$("#etape").live('pageshow', function() {

    if(index>5)
    {
    //Go to other Page
    }

    switch(id_type_champ)
    {
        case 1:
            $('#header-right-container').append(''+nom_champ+'<input type="text" id='+Id+'  >  ').trigger("create");
            alert("case 1");
            break;
        case 2:
            $('#header-right-container').append(''+nom_champ+'<input type="text" id='+Id+' > ').trigger("create");
            alert("case 2");
            break;
        case 3:
            $('#header-right-container').append(''+nom_champ+'<input type="date" id='+Id+' OnClick="aff_date(\'' + Id + '\')">').trigger("create");
            alert("case 3");
            break;
        case 4:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+'    ><option value=0></option></select>').trigger("create");
            alert("case 4");
            break;
        case 5:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 5");
            break;
        case 6:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 6");
            break;
        case 7:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 7");
            break;
        case 8:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 8");
            break;
        case 9:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 1");
            break;
        default:
            $('#header-right-container').append(''+nom_champ+'<select id='+Id+' ><option value=0> </option></select> ').trigger("create");
            alert("case 1");
            break;
    }

    $('#header-left-container').append('<a href="etape.html" data-role="button"  OnClick="DoAction()" data-icon="arrow-r"    data-iconpos="right"  data-theme="a" id="suivant">Suivant</a> ').trigger("create");
}

function DoAction()
{
    //$('#'+id+'').val() ;        //GET text
    //$('#'+id+'').val('AAAAAA'); //SET
    index++;
    alert('Button has been clicked avec un index =  a '+ index);
}
4

1 に答える 1

0

コードが表示されませんが、同じ ID を持つ複数の HTML 要素を追加していないことを確認します。ID は一意である必要があります。

<select id='+Id+' >

2 回目の反復でリセットされる Id aa カウンターですか? 2 番目の反復が実行される前に、最初の反復はどこかに保存され、削除されませんか? firebug などを使用して確認してください。

于 2012-11-19T13:25:17.977 に答える