2013-03-05 69 views
0
  <link type="text/css" rel="stylesheet" href="scripts/jquery-ui-1.8.5.custom.css" /> 
     <script src="Scripts/jquery-1.4.2.js" type="text/javascript"></script> 
     <script type="text/javascript" src="scripts/jquery-ui-1.8.5.custom.min.js"></script> 


    <script type="text/javascript"> 
    function getalert1(Leave_RegisterID) 
      { 
       document.getElementById('<%= hdnLeave_RegID.ClientID %>').value = Leave_RegisterID; 
       $.fx.speeds._default = 1000; 
       $(function() { 
        $('#reason').dialog({ 
         autoOpen: false, 
         show: "blind", 
         hide: "explode", 
         display: '' 
        }); 
        $('.LeaveReason1').click(function() 
        { 
         $('#reason').html(); 
         $('#reason').dialog('open'); 
         return false; 
        }); 
       }); 
      } 
</script> 

,我按一下按鈕:JQuery的對話框中的瀏覽器不開放

 <button id="LeaveReason1" class="LeaveReason1" onclick="getalert1('<%# Eval("Leave_RegisterID") %>');" title="Decline">Decline</button> 

然而,當我在Firebug調試它不會得到這個代碼裏面,它應該:

$('#reason').html(); 
    $('#reason').dialog('open'); 
    return false; 

HTML

<div id="reason" style="height: 300px; min-height: 109px; width: auto; display:none;" class="ui-dialog-content ui-widget-content" runat="server"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
       <tr> 
        <td width="25%" class="body_txt" style="padding-right:2px"> 
         <asp:Label ID="lblReason" runat="server" Text="Reason:" ></asp:Label> 
        </td> 
        <td width="75%"> 
         <asp:TextBox ID="txtReason" Height="40%" Width="100%" MaxLength="200" TextMode="MultiLine" runat="server" CssClass="txt_bx" ></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="2">&nbsp;</td> 
       </tr>      
       <tr> 
        <td colspan="2" align="center"> 
         <asp:Button Width="30%" runat="server" Text="Submit" id="btnSubmit" Height="25px" CssClass="clButton" ></asp:Button>&nbsp;&nbsp;&nbsp; 
        </td> 
       </tr> 
      </table> 
     </div> 
+0

你沒寫裏面標籤的功能。你的原始代碼中有這個錯誤嗎? – luckystars 2013-03-05 05:01:52

回答

0

它不會進入上述給定的代碼內..因爲你有另一個點擊事件內的代碼..基本上是爲了工作,你必須再次點擊相同的按鈕....這將無法正常工作..

試試這個

function getalert1(Leave_RegisterID) // you are calling this function whn click 
    { 
     document.getElementById('<%= hdnLeave_RegID.ClientID %>').value = Leave_RegisterID; 
     $.fx.speeds._default = 1000; 
     //$(function() { and no need of ready function here 
      $('#reason').dialog({ 
       autoOpen: false, 
       show: "blind", 
       hide: "explode", 
       display: '' 
      }); 

      // $('.LeaveReason1').click(function() { again you have a click event here which is not necessary at all.. since the click is already fired by getalert1() 
       $('#reason').html(); 

       $('#reason').dialog('open'); 
       return false; 

     }); 
    } 
+0

它不工作頁面只刷新 – vini 2013-03-05 05:07:04

+0

調試它,看到....'console.log('here')'內'getalert11()'並檢查它是否進入函數內部...讓我知道。 .. – bipen 2013-03-05 05:10:06

+0

是的,它進入功能。它移動了整個功能,但頁面只是刷新到最後 – vini 2013-03-05 05:19:57

0
$(document).ready(function(){ 

//separate your dialog init 
$(function() { 
    $('#reason').dialog({ 
     autoOpen: false, 
     show: "blind", 
     hide: "explode" 
    }); 
}); 

//only have one click event 
$('.LeaveReason1').click(function() 
       { 
     document.getElementById('<%= hdnLeave_RegID.ClientID %>').value = Leave_RegisterID; 
       $.fx.speeds._default = 1000; 

        $('#reason').html(); 
        $('#reason').dialog('open'); 
        return false; 
       }); 
+0

但我在按鈕上調用此功能,爲什麼要把它放在document.ready – vini 2013-03-05 05:16:42

+0

只是確保。當頁面中的所有內容被加載時,document.ready都會觸發。我們不希望將點擊事件分配給尚不存在的事件。但這不是這裏的重點,只是習慣於這樣做.. – 2013-03-05 05:22:52