2014-10-22 7 views
0

x-editablehttp://vitalets.github.io/x-editable/index.html jquery inplace 편집기를 사용하고 있습니다. 다음과 같은 결과동일한 ID 이름에서 값 지정 및 가져 오기

<?php 
    $num_rows = 1; 
    // store the record of the "tblstudent" table into $row 
    while ($row = mysqli_fetch_array($result)) { 

     echo "<script type=\"text/javascript\"> 
     $.fn.editable.defaults.mode = \"popup\";      
     $('#username$num_rows').editable();   

     </script> "; //assign num to element 

     // Print out the contents of the entry 

     echo '<tr>'; 
     echo '<td><a href="#" id="username' . $num_rows . '" data-type="text" data-pk="' . $row['id'] . '" data-url="post.php" data-title="Edit website">'; 
     echo htmlspecialchars($row['website'], ENT_QUOTES, 'UTF-8'); 
     echo '</a></td>'; 
     echo '</tr>'; 
     $num_rows++; 
    } 
?> 

:

enter image description here

을하지만 보시다시피 나는 요소 ID를 할당하고 자바 스크립트로 ID를 얻기에 $num_rows을 사용하여 현재 내가 일하는 코드를 아래와 같이 있습니다. 나는 요소에 uniq ID를 할당하거나 php 태그에 javascript를 포함하기 위해 루프를 사용하지 않는 것을 선호합니다. 이것보다 우아한 해결책이 있습니까?

미리 감사드립니다.

+0

왜 ID가 필요합니까? 의도는 jquery 'click'이벤트를 사용하여 수행 할 수있는 클릭 된 요소를 파악하는 것입니다. –

+0

데이터 속성에 db ID를 사용하여 같은 행을 업데이트하는 간단한 식별자를 갖도록하십시오. – charlietfl

답변

1

id 대신 username을 입력하거나 id 대신 class='username'을 추가하십시오.

<script type="text/javascript"> 

    $.fn.editable.defaults.mode = "popup"; 

    $('.username').click(function(){ 

     $(this).editable(); 

    }) 


</script> 
+0

클래스와 ID'username'을 모두 추가하면 작동합니다. 감사. 결국 수업에 대한 나의 이해가 잘못되었습니다. – sg552