2011-05-09 24 views
0

有沒有辦法從jqueryMobile對話框中獲取返回值?這裏是jQueryMobile文檔的簡單代碼,但不能完全工作。如何從jQueryMobile對話框中獲取返回值?

指數

<link rel="stylesheet" href="jquery.mobile-1.0a4.1.css" /> 
<script src="jquery-1.5.2.min.js"></script> 
<script src="jquery.mobile-1.0a4.1.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    $('.delete-dialog-yes').click(function() { 
     alert("delete-dialog-yes"); 
    }); 
    $('.delete-dialog-no').click(function() { 
     alert("delete-dialog-no"); 
    }); 
}); 
</script> 
</head> 
<body> 
<div data-role="page" id="my-page"> 
    <div data-role="content"> 
     <a href="delete-dialog.cfm" data-role="button" data-rel="dialog" data-transition="pop">Show Dialog</a> 
    </div> 
</div> 

對話框

<link rel="stylesheet" href="jquery.mobile-1.0a4.1.css" /> 
<script src="jquery-1.5.2.min.js"></script> 
<script src="jquery.mobile-1.0a4.1.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    $('.delete-dialog-yes').click(function() { 
     alert("delete-dialog-yes"); 
    }); 
    $('.delete-dialog-no').click(function() { 
     alert("delete-dialog-no"); 
    }); 
}); 
</script> 
<title>Dialog</title> 
</head> 
<body> 
<div data-role="page" id="delete_dialog" data-theme="b"> 
    <div data-role="content" data-theme="b"> 
     <h1>Delete Item?</h1> 
     <p>Are you sure you want to delete this item?</p> 
     <a href="#" class="delete-dialog-yes" data-role="button" data-theme="b">Yes</a> 
     <a href="#" class="delete-dialog-no" data-role="button" data-theme="b">No</a> 
    </div> 
</div> 

回答

2

在對話框頁面的<script>標籤沒有得到評估,因爲JQueryMobile加載這個頁面動態,並從它使用的只是div data-role=page 。您可以刪除該部分。

在您的索引頁中的<script>標記中,您對尚未存在的元素使用.click,所以顯然它什麼也不做。您可以使用live代替:

<script type="text/javascript"> 
    $(document).ready(function() { 
    $('.delete-dialog-yes').live('click',function() { 
     alert("delete-dialog-yes"); 
    }); 
    $('.delete-dialog-no').live('click',function() { 
     alert("delete-dialog-no"); 
    }); 
    }); 
</script> 
相關問題