开发者

getting value from jquery dialog

So i am using ajax jquery .load() functi开发者_Python百科on to retrieve books using their ISBN the id in a jquery dialog. I am trying to return the value to a input box on the page the dialog is being opened on with no luck. When i click the links, nothing happens. Below is my jquery code.

      <script type="text/javascript">
$(document).ready(function(){

     // dialog init
    $('.choosebookbox').dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        width: 600,
        height:600,
        title: 'Choose a book',
        overlay: { backgroundColor: "#000", opacity: 0.5 }
    });
    // click event
     $('a#booksearch_lnk').click(function(){
            $('.choosebookbox').dialog('open').css('display','block');
                $('#tab2').load('post/topsellers.php');
                $('#tab1').load('post/newbooks.php');

                 $('a.choosebook').click(function(){
                    // alert($(this).attr('id'));
                    $("#isbn").val($(this).attr('id'));
                    $('.choosebookbox').dialog("close");
                });
        });
});
    </script>

and a sample book link that appears in the modal/dialog...

<a id="0439064864" class="choosebook" href="#">Harry Potter and the Chamber of Secrets (Book 2)</a>


A guess is that your links are loaded with your ajax and so do not belong to the DOM initially. In this case try the live function.

$('a.choosebook').live("click", function() {
  //do stuff
});

Did your commented out alert display anything?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜