2010-12-14 3 views
0

데이터베이스 호출의 레코드를 나열하는 페이지가 있습니다. 나는 행을 편집 할 수 있도록 Jquery 대화 상자를 팝업 할 각 행에 '편집'링크가 있어야합니다. 내 질문은 편집 할 수 있도록 선택한 행의 데이터를 jquery 대화 상자로 전달하는 방법입니다. jquery 팝업을 열지 만 텍스트 상자가 비어있는 코드가 있습니다.jquery를 사용하여 데이터 업데이트

<div id="boxes"> 

<div id="dialog2" class="window"> 
<form method="post" action="update_books_a.php"> 
    <input name="name" type="text" value="<?php echo $ing['book_name']; ?>"/>
<input name="author" type="text" value="<?php echo $ing['author']; ?>"/> <input type="hidden" name="book_id" value="<?php print $ing['book_id'];?>" />

<input type="submit" value="Update" class="close"/> </form> </div>

myphp 코드는 jQuery 코드가




$(document).ready(function() { 

    //select all the a tag with name equal to modal 
    $('a[name=modal]').click(function(e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     //Get the A tag 
     var id = $(this).attr('href'); 

     //Get the screen height and width 
     var maskHeight = $(document).height(); 
     var maskWidth = $(window).width(); 

     //Set heigth and width to mask to fill up the whole screen 
     $('#mask').css({'width':maskWidth,'height':maskHeight}); 

     //transition effect 
     $('#mask').fadeIn(1000); 
     $('#mask').fadeTo("slow",0.8); 

     //Get the window height and width 
     var winH = $(window).height(); 
     var winW = $(window).width(); 

     //Set the popup window to center 
     $(id).css('top', winH/2-$(id).height()/2); 
     $(id).css('left', winW/2-$(id).width()/2); 

     //transition effect 
     $(id).fadeIn(2000); 

    }); 

    //if close button is clicked 
    $('.window .close').click(function (e) { 
     //Cancel the link behavior 
     e.preventDefault(); 

     $('#mask').hide(); 
     $('.window').hide(); 
    }); 

    //if mask is clicked 
    $('#mask').click(function() { 
     $(this).hide(); 
     $('.window').hide(); 
    }); 

}); 



body { 
font-family:verdana; 
font-size:15px; 
} 

a {color:#333; text-decoration:none} 
a:hover {color:#ccc; text-decoration:none} 

#mask { 
    position:absolute; 
    left:0; 
    top:0; 
    z-index:9000; 
    background-color:#000; 
    display:none; 
} 

#boxes .window { 
    position:absolute; 
    left:0; 
    top:0; 
    width:440px; 
    height:200px; 
    display:none; 
    z-index:9999; 
    padding:20px; 
} 



#boxes #dialog2 { 
    background:url(../images/notice.png) no-repeat 0 0 transparent; 
    width:326px; 
    height:229px; 
    padding:50px 0 20px 25px; 
}

답변

0

당신은 .text() 방법을 이용하여 각 요소의 텍스트 값을 추출 할 수있다

$select=mysql_query("select * from books where book_id='$book_id'") or die(mysql_error()); 
while($ing=mysql_fetch_array($select)) 
{ 
?> 
<tr> 
    <td><a href="#dialog2" name="modal"><?php echo $ing['book_name'];?></a></td> 
    <td><?php echo $ing['author'];?></td></tr> 

이다.
html 값이 필요한 경우 .html() 또는 yourNode.innerHTML을 사용할 수 있습니다.

+0

을 그리고 ('.val를 사용하여 텍스트 상자에 텍스트를 충실

당신이 줄 끝에서, 당신의 클릭 처리기에 코드를 추가해야) ' –

+0

newibi jquery 여기에 귀하의 요점을 could't – hunter

0

테이블에 book_id가 없으므로 숨겨진 입력을 채울 수 없습니다. 그러나 아래의 코드는 book_name과 저자를 위해 그것을하는 법을 보여 주므로 시작하기에 충분합니다.

//Cancel the link behavior 
e.preventDefault(); 

이 코드 추가 :

// Copy book_name 
$("#dialog2 input[name=name]").val($(this).text()); 

// Copy author 
$("#dialog2 input[name=author]").val($(this).parent().next("td").text()); 
관련 문제