2012-07-06 31 views

回答

16

最簡單的形式,你可以使用提示(問題,默認): (取自W3Schools的:http://www.w3schools.com/js/tryit.asp?filename=tryjs_prompt

function myFunction(){ 
    var x; 
    var name=prompt("Please enter your name","Harry Potter"); 
    if (name!=null){ 
     x="Hello " + name + "! How are you today?"; 
     alert(x); 
    } 
} 

什麼都需要大量的JavaScript & CSS來創建按鈕層並點擊這些按鈕事件

+0

真棒,完美的作品,但我想知道是否可能使這個盒子大,像一個方形的文本輸入框? – Mark 2012-07-06 14:21:46

+1

nope,這是一個瀏覽器特定的窗口。就像我說的,你必須使用javascript/CSS來創建這樣的盒子。可能有庫可用於此,如jQuery UI http://jqueryui.com/demos/dialog/ – 2012-07-09 13:27:20

0

script標籤之間的代碼的head標籤內粘貼

HTML

<button id="button">Get Text</button>​ 

JS

window.onload=function() 
{ 
    var el=document.getElementById('button'); 
    el.onclick=function(){ 
     var my_text=prompt('Enter text here'); 
     if(my_text) alert(my_text); // for example I've made an alert 
    } 
} 

DEMO.