2013-09-26 253 views
2

只注意到它的作品,當我禁用CSS 任何人都可以解釋爲什麼?使用按鈕點擊複製文本與零剪貼板

我正在使用零剪貼板將文本框的值複製到剪貼板。

我可以使它在普通的HTML頁面上工作,但是當我在aspx頁面上應用相同的代碼時,它不能按預期工作。

讓我先解釋一下如何在普通的html頁面上工作。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Locker.test" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    <asp:Button ID="Button1" runat="server" Text="Button" />  
    </form> 

      <script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script> 
      <script type="text/javascript" src="Scripts/jquery.zclip.js"></script> 
      <script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script> 
       <script> 
        $(document).ready(function() { 
         $('#<%=Button1.ClientID%>').zclip({ 
          path: 'ZeroClipboard.swf', 
          copy: function() { return $('#<%=TextBox1.ClientID%>').val(); } 
         }); 
        }); 
       </script> 
</body> 
</html> 

它將無論在文本框中鍵入的任何內容複製到剪貼板。

當我右鍵單擊按鈕,我可以看到它連接到Zeroclipboard閃光燈。 enter image description here

現在,如果我實現了鏈接到母版頁這是行不通的aspx頁面上相同,

我覺得zerocliboard未初始化。

當我右鍵點擊按鈕,我看到不同。 (必須是上面來完成這項工作。)

enter image description here

aspx頁面上的代碼如下:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="searchResult.aspx.cs" Inherits="Locker.searchResult" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"> 
    <style type="text/css"> 
     .auto-style1 { 
      color: #FFFFFF; 
      font-size: large; 
     } 
     .auto-style2 { 
      color: #000000; 
     } 
     .auto-style3 { 
      color: #000000; 
      font-size: large; 
     } 
    </style> 
</asp:Content> 

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server"> 

     &nbsp;<p> 

     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<p> 
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong> <span class="auto-style3">Information</span><span class="auto-style1">&nbsp;&nbsp;&nbsp;</span></strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
     <div style="width:70%; margin: auto auto; text-align:left;"> 
      <asp:Panel ID="Panel1" runat="server"> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label4" runat="server" style="font-weight: 700; font-size: large" Text="Details for :" CssClass="auto-style2"></asp:Label> 
      <asp:Label ID="Label5" runat="server" style="font-weight: 700; font-size: large; color: #0000FF"></asp:Label> 
      <br /> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label1" runat="server" Font-Bold="False" style="font-weight: 700; font-size: large" Text="Password :" CssClass="auto-style2"></asp:Label> 
      &nbsp;<asp:TextBox ID="TextBox2" runat="server" BorderStyle="Solid" Enabled="False" Font-Size="Medium" ForeColor="Black" Width="213px"></asp:TextBox> 

       &nbsp; 

       <asp:Button ID="Button3" runat="server" Text="Button" />    
       <input type="text" id="test_description" value="hi" /> 

      <script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script> 
      <script type="text/javascript" src="Scripts/jquery.zclip.js"></script> 
      <script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script> 
       <script> 
       window.onload = $(document).ready(function() { 
         $('#<%=Button3.ClientID%>').zclip({ 
          path: 'ZeroClipboard.swf', 
          copy: window.onload = function() { return $('#<%=TextBox2.ClientID%>').val(); } 
         }); 
        }); 
       </script> 
      <br /> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
      <asp:Label ID="Label6" runat="server" style="font-weight: 700; font-size: large" Text="Description :" CssClass="auto-style2"></asp:Label> 
      &nbsp;<asp:TextBox ID="TextBox5" runat="server" BorderStyle="Solid" Enabled="False" Font-Size="Medium" Height="48px" TextMode="MultiLine" Width="213px"></asp:TextBox> 
      <br /> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:Label ID="Label7" runat="server" style="font-weight: 700; font-size: small" Text="Last Editor was " CssClass="auto-style2"></asp:Label> 
      <asp:Label ID="Label8" runat="server" style="font-weight: 700; font-size: small" CssClass="auto-style2"></asp:Label> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Edit" Width="97px" /> 
      <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" Visible="False" Width="97px" /> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:Label ID="Label12" runat="server" style="font-weight: 700; font-size: large; color: #0000FF" Visible="False"></asp:Label> 
      <br /> 
      <br /> 
      <br /> 
      <br /> 
      &nbsp;&nbsp;&nbsp;&nbsp; 
    </asp:Panel> 

     </div> 
</asp:Content> 

有誰知道問題是什麼,這可怎麼解決?

從HTML頁面檢查結果 enter image description here

從普通頁面 enter image description here

+0

只需檢查ZeroClipboard.swf的路徑或嘗試將絕對網址用於測試。 –

+0

我認爲你是對的,但我不確定爲什麼它沒有加載到一個頁面,而不是其他。通過上面的瀏覽器捕捉 –

+0

嘗試爲'path:'http:// localhost:port /.../ ZeroClipboard.swf',' –

回答

1

檢查結果在你的輸出尋找「從普通頁面檢查結果」,我可以看到,「TextBox2中」被禁用(而它應該被啓用)並且它也具有應用於它的CSS類「aspNetDisabled」。這很可能是導致ZeroCopy工具失敗的「aspNetDisabled」類,因爲當您關閉CSS時,該功能將起作用。

注意「檢查HTML頁面結果」中的「TextBox1」未被禁用。

因此,要確保ASPX頁面中的「TextBox2」已將「Enabled」設置爲True,請執行此操作。

此外,請確保您使用Flash的瀏覽器上安裝了Flash,因爲ZeroClipboard使用「不可見的Adobe Flash影片」。

最後,刪除「在window.onload」即代碼更改爲:

$(document).ready(function() { 
$('#<%=Button3.ClientID%>').zclip({ 
    path: 'ZeroClipboard.swf', 
    copy: function() { return $('#<%=TextBox2.ClientID%>').val(); } 
}); 
}); 

因爲我不認爲它會與ZeroClipboard庫工作。

+0

嘗試了您的建議,但它不起作用 –

+0

也在Internet Explorer中嘗試過,但沒有在其他瀏覽器上嘗試過 –

+0

這可能是因爲Flash在IE中已安裝,但未在其他瀏覽器中安裝。檢查Flash是否安裝在其他瀏覽器上(可以使用[this](https://www.adobe.com/software/flash/about/)鏈接)。 –