Jquery的ThickBox插件非常好用,可以顯示一張圖片、多張圖處、AJAX和IFrame等多種樣式的內容到ThickBox,都要A click觸發,而有的時候后臺程序根據不同權限顯示不同內容,這時希望根據條件輸入框的值判斷是否顯示ThickBox的內容,所需添加代碼如下:

<script type="text/javascript" src="<web.path:path/>/resources/js/jquery.js"></script>
<script type="text/javascript" src="<web.path:path/>/resources/js/thickbox.js"></script>
<link rel="stylesheet" href="<web.path:path/>/resources/css/thickbox.css" type="text/css" media="screen" />
<script type="text/javascript">
??? $(function(){
???????
??????? //init thickbox的默認選擇器
?? ???? tb_init('a.thickbox, area.thickbox, input.thickbox');
?? ???? $("#thickButton").click(function(event){
?? ???? ???
?? ???? ??? event.preventDefault();
??????????? //如果name輸入框的值不為空, 則彈出thickBox對話框
?? ???? ??? if($("#name").val()!="") {
?? ???? ??? ??? tb_show("","url?height=300&width=400&inlineId=myOnPageContent",false);
?? ???? ??? }
?? ???? });
?? ?});
</script>

<input type="text" id="name"/>
<input title="ban another user" type="button" value="Show" id="thickButton"/>