2016-05-30 36 views
1

我有一個按鈕。當我點擊那個按鈕時,出現一個彈出的CSS框,它有一個包含一些數據的文本框。我希望在彈出框打開後立即選擇這些數據。我嘗試在jQuery中使用.select()函數,但它似乎並沒有工作。使用Jquery在彈出框中選擇文本

這是按鈕: -

<div id="copyBox" style="display:inline-block; margin-left: 10px;"> 
    <button class="btn copy-button" id="obj" data-clipboard-text="Take data from URL and put it here using Jquery" > 
     <a href="#openModal" style="color: #fff;">Copy URL</a> 
    </button> 
</div> 

這是彈出框: -

<div id="popup1" class="overlay"> 
    <div class="popup"> 
     <span class="poptext">Copy URL to share the link</span> 
     <a class="close" href="#">&times;</a> 
     <div class="content"> 
      <input type="text" id="urlText" style="width:90%;"> 
     </div> 
    </div> 
</div> 

這就是我使用jQuery: -

$("#obj").click(function() { 
    $("#urltext").select(); 
}); 

我不不知道我要去哪裏錯了。任何人都可以幫我解決這個問題嗎?jquery

+0

您的JQuery選擇器是錯誤的。 #urltext會是對的。同樣用select()你試着註冊一個事件處理程序,這幾乎肯定不是你想要的。你正在尋找的功能是val()。 –

+0

明確說明你想要.. –

+0

當我點擊按鈕時,應該選擇文本框中的URL(URL在文本框中),以便我可以使用Ctrl + C複製該數據而不是先手動選擇,然後複製。或者,如果我只是點擊文本字段,數據會被選中進行復制(就像在Google環聊共享鏈接中發生的那樣) –

回答

相關問題