Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

javascript - React v16.5.2-在随后无条件刷新屏幕的情况下引发弹出消息(React v16.5.2 - Raising a popup message with an unconditional screen refresh afterwards)

I have a requirement to display a popup message (similiarly to the outcome of the "confirm" function of Alertify.js), and to unconditionally refresh the screen after the popup is being closed by the user, whether it is done through the 'X' or the 'OK' button.

(我需要显示一个弹出消息(类似于Alertify.js的“确认”功能的结果),并且在用户关闭弹出窗口后是否无条件刷新屏幕,无论是否通过'X完成”或“确定”按钮。)

Basically, the "confirm" function proposed by Alertify.js adheres to my need except its "Cancel" button (as it does nothing after the user clicks on it).

(基本上,Alertify.js提出的“确认”功能除了它的“取消”按钮外一直符合我的需要(因为在用户单击该按钮后它什么也不做)。)

If I could get rid of the cancel button somehow that would be great, but I'm not sure how to or if I'm even able to at all.

(如果我能以某种方式摆脱取消按钮,那将是很好的选择,但是我不确定如何或者我什至无法做到。)

What work-around would you suggest to that matter?

(您对此有何建议?)

I tried this code,

(我尝试了这段代码,)

alert("Successful Message");
location.reload();

This code causes the screen to refresh but doesn't show the alert.

(此代码导致屏幕刷新,但不显示警报。)

I guess the second line doesn't wait for the alert message to be closed and just immediately reloads the screen.

(我猜第二行不会等待警报消息关闭,而只是立即重新加载屏幕。)

Thanks in advance!

(提前致谢!)

  ask by Adi hahanov translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here you have a working demo :)

(在这里,您有一个有效的演示:))

[i see that you are new so click on the BLUE BUTTON 'Run code snippet', and comment if it worked ]

([我发现您是新手,所以请点击蓝色按钮“运行代码段”,然后评论是否可行])

 function myFunction() { var txt; if (confirm("Press a button!")) { txt = "You pressed OK!"; } else { txt = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = txt; } 
 <!DOCTYPE html> <html> <body> <h2>JavaScript Confirm Box</h2> <button onclick="myFunction()">Try it</button> <p id="demo"></p> </body> </html> 


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...