2017-02-26 84 views
1

所以基本上我想實現一個功能,即當有人訪問我的網站時,它會彈出兩個選項(選擇他們想要的語言)來歡迎他們。當有人進入網站時彈出一個彈出框

這將是這個樣子:

Desired output

我不知道我怎麼會去這一點,所以有人請讓我知道我怎麼可能去實現這樣的事情?謝謝!

+2

你好,請閱讀[?如何我問一個很好的問題(HTTP://計算器.com/help/how-to-ask),對此進行嘗試,然後詢問您遇到的問題以及您需要幫助的問題。還要將「java」標記更改爲「javascript」 - 它們是不同的語言並且彼此不相關。 –

+1

預計你至少試圖爲自己編碼。堆棧溢出不是代碼寫入服務。我建議你做一些[**額外的研究**](http://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) ,無論是通過谷歌或通過搜索,嘗試和。如果您仍然遇到麻煩,請返回**您的代碼**並解釋您所嘗試的內容。 –

+0

究竟..或者爲了幫助你一點,搜索一個「簡單的html模式窗口」..這是你需要的。 – MilMike

回答

0

這適用於我。我不知道這是否是最好的方式。

HTML:

<div id="grayout"></div> 
<div id="popup"> 
    <button type="button" id="language1">Language 1</button> 
    <button type="button" id="language2">Language 2</button> 
</div> 
<!-- your page HTML here --> 

CSS:

#grayout { 
     position:fixed; 
     height:100%; 
     width:100%; 
     background-color:rgba(0,0,0,.5); 
    } 
    #popup { 
     position:fixed; 
     height:50%; 
     width:50%; 
     background-color:white; 
     left:25%; 
     top:25%; 
    } 
    #language1 { 
     position:absolute; 
     top:50%; 
     left:25%; 
    } 
    #language2 { 
     position:absolute; 
     top:50%; 
     right:25%; 
    } 

的JavaScript:

document.getElementById('language1').onclick = function() { 
     document.getElementById('popup').style.display = "none"; 
     document.getElementById('grayout').style.display = "none"; 
     //selected language1 code here 
    }; 
    document.getElementById('language2').onclick = function() { 
     document.getElementById('popup').style.display = "none"; 
     document.getElementById('grayout').style.display = "none"; 
     //selected language2 code here 
    };