컨테이너를 클릭하여 그에게 관한 몇 가지 필드의 값을 업데이트 할 수있는 가능성을 사용자에게 제공하려고합니다. # info-client 여기에 입력 영역을 추가합니다. 클릭 한 번 #finish 버튼을 클릭하면 정보가 업데이트됩니다. 내가 가진 문제는 그것을요소를 추가하고 replaceWith() - jQuery
$("#info-client").one('click', function() {
$("#info-client").children().hide();
// liste des champs
var c1 = $('<label> Nom : </label><input type="text id="identifiant"> <br>');
var c2 = $('<label> Adresse : </label><input type="text" id="adresse"><br>');
var c3 = $('<label> Ville : </label><input type="text" id="ville"><br>');
var c4 = $('<label> Tel : </label><input type="text" id="tel"> <br>');
var c5 = $('<label> Fax : </label><input type="text" id="fax"> <br>')
var button = $('<input type="button" id="finish" value="Mettre à jour">');
$("#info-client").append(c1);
$("#info-client").append(c2);
$("#info-client").append(c3);
$("#info-client").append(c4);
$("#info-client").append(c5);
$("#info-client").append(button);
$("#finish").one('click', function() {
var identifiant = $('#identifiant').val();
var adresse = $('#adresse').val();
var ville = $('#ville').val();
var tel = $('#tel').val();
var fax = $('#fax').val();
c1.replaceWith("<h4>" + identifiant + "</h4>");
c2.replaceWith("<p> Adresse : " + adresse + "</p>");
c3.replaceWith("<p>" + ville + "</p>");
c4.replaceWith("<p>Fax : " + tel + "</p>");
c5.replaceWith("<p> Tel :" + fax + "</p>");
});
});
http://jsfiddle.net에서 문제의 예를 설정할 수 있습니까? 또는 적어도 질문에 –
HTML을 추가하십시오 : https://jsfiddle.net/3h79cv7o/ –
'$ ("# info-client")'가 DOM 요청을하고 jQuery를 생성한다는 것을 알아야합니다. 그것이 실행될 때마다 객체가됩니다. 캐싱을 통해 코드를 크게 최적화 할 수 있습니다 :'var $ infoClient = $ ("# info-client"); $ infoClient.somestuff(); $ infoClient.otherStuff();'명령어를 연결할 수도 있습니다 :'$ infoClient.append (c1) .append (c2) .append (c3)' –