第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

為什么在prompt窗口點了取消還是會打開新窗口的

function?openWindow(){
????????var?clickConfirm?=?confirm("是否打開網(wǎng)址輸入框?");
????????if?(clickConfirm?==?true){
????????????var?link?=?prompt("Please?input?the?website?address:","https://qq.com");
????????????window.open(link,'_blank','width=500,height=600');
????????}
????????else?{
????????????alert("helloworld");
????????}
????}

我想實現(xiàn)點擊確認(rèn)打開新窗口,點擊取消彈alert,但是好像不行。


另外我想嘗試:

1、點擊按鈕先彈prompt窗口;點擊確認(rèn)再彈出confirm窗口;點擊取消彈alert

2、彈出confirm窗口,點擊確認(rèn)打開新網(wǎng)頁窗口,點擊取消彈alert

試了很多個方式,但是都會提示else錯誤等等,無法正常實現(xiàn)我需要的功能。比如如下代碼:

function?openWindow(){
????????var?link?=?prompt("Please?input?the?website?address:","https://qq.com");
????????if?(prompt?==?true){
????????????var?clickConfirm?=?confirm("是否打開網(wǎng)址輸入框?");
????????????if?(clickConfirm?==?true){
????????????????window.open(link,'_blank','width=500,height=600');
????????????}
????????????else?{
????????????????alert("helloworld");
????????????}
????????}
????????else?{
????????????alert("helloworld");
????????}
????}

請大家指點一下,謝謝

正在回答

3 回答

你第一個代碼段沒有問題,可以按照預(yù)期運行;:如果你把if?(clickConfirm == true)誤打成if?(clickConfirm = true)就會出現(xiàn)你描述的問題,這段代碼和你測試時的代碼是否不同?你第二個代碼段錯在對prompt方法返回值的理解。下面的代碼是對你的描述的一種實現(xiàn):

<!DOCTYPE?html>
<html>
?<head>
??<title>?new?document?</title>??
??<meta?http-equiv="Content-Type"?content="text/html;?charset=gbk"/>???
??<script?type="text/javascript">??
????function?openWindow(){
????
????//?通過prompt方法,輸入要打開的網(wǎng)址,默認(rèn)為?http://idcbgp.cn/
????????var?link?=?prompt("請輸入網(wǎng)址:",?"http://idcbgp.cn");
????????//prompt方法點擊取消返回null
????????if(link?==?null){
????????????alert("prompt方法點擊取消");
????????}
????????//prompt方法點擊確認(rèn)返回字符串,(包括空字符串"")
????????else{
????????????//彈出確認(rèn)框,確認(rèn)是否打開網(wǎng)址
????????????var?confirmMessage?=?confirm("確認(rèn)打開網(wǎng)址?")
????????????//confirm方法點擊確認(rèn)返回布爾值true,點擊取消返回布爾值false
????????????if(confirmMessage){
????????????????//打開的窗口要求,寬400像素,高500像素,無菜單欄、無工具欄。
????????????????window.open(link,?"_blank",?"width=500,?height=600");
????????????}
????????????else{
????????????????alert("confirm方法點擊取消");
????????????}
????????}
????}
??</script>?
?</head>?
?<body>?
??????<input?type="button"?value="新窗口打開網(wǎng)站"?onclick="openWindow()"?/>?
?</body>
</html>


2 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Summving 提問者

謝謝解答,根據(jù)你的解答后重寫了第一段后可以正常工作了。
2020-10-20 回復(fù) 有任何疑惑可以回復(fù)我~

重寫了第一段代碼:

<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>alert</title>
??<script?type="text/javascript">
??function?rec(){
????var?confirmMessage?=?confirm("do?you?want?to?open?the?address?dialog?");
????if?(confirmMessage){
????????var?link?=?prompt("please?input?the?link:","http://idcbgp.cn");
????????if?(link?==?null){
????????????alert("You?are?cancel?the?prompt?dialog!");
????????}
????????else?{
????????????window.open(link,"_blank","width=500,height=600");
????????}
????}
????else?{
????????alert("You?are?cancel?the?confirm?dialog!");
????}
??}
??</script>
</head>
<body>
????<input?name="button"?type="button"?onClick="rec()"?value="點擊我,彈出對話框"?/>
</body>
</html>


根據(jù)樓上熱心朋友的解答,寫了第二段:

<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>
<title>alert</title>
??<script?type="text/javascript">
??function?rec(){
????var?inputLink?=?prompt("please?input?your?link:","http://idcbgp.cn");
????if?(inputLink?!==?null){
????????var?confirmMessage?=?confirm("Do?you?confirm?to?open?this?link?");
????????if(confirmMessage){
????????????window.open(inputLink,"_blank","width=500,?height=500");
????????}
????????else?{
????????????alert("You?are?cancel?to?open?this?link!");
????????}
????}
????else?{
????????alert("You?are?cancel?to?open?the?link?directly!")
????}
??}
??</script>
</head>
<body>
????<input?name="button"?type="button"?onClick="rec()"?value="點擊我,彈出對話框"?/>
</body>
</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~

prompt的返回值是字符串或者null。所以第三行應(yīng)該是prompt(link!=null)

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Summving 提問者

謝謝解答,if(prompt(link!=null)) 和 if (link !== null) 不一樣,用后者才可以正常工作。
2020-10-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

為什么在prompt窗口點了取消還是會打開新窗口的

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號