Javascript 单击框时使用js弹出

Javascript 单击框时使用js弹出,javascript,html,css,Javascript,Html,Css,我创建了一个简单的网站,它将成为一个更大项目的一部分: 以下是屏幕截图: 代码如下: <!DOCTYPE html> <html> <head> <script type="text/javascript"> function popup () { var thought = prompt("Please enter your thougt"); } </script> <style> .fi

我创建了一个简单的网站,它将成为一个更大项目的一部分: 以下是屏幕截图: 代码如下:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
    function popup () {
        var thought = prompt("Please enter your thougt");
    }
</script>
<style>
.fixed-size-square {
    display: table;
    width: 200px;
    height: 200px;
    background: green;
}
.fixed-size-square span {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    color: white
}
.size-square {
    display: table;
    width: 200px;
    height: 200px;
    background: green;
}
.size-square span {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    color: white
}
.square {
    display: table;
    width: 200px;
    height: 200px;
    background: green;
}
.square span {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
    color: white
}
.fixed-size-square, .size-square, .square {
    float: left;
    margin: 20px;
    zoom: 1; 
    position: relative;
    box-shadow: 10px 10px 5px #888888;
    /*position: absolute;*/
    /*margin: auto;*/
}
button {
        position: relative;
        margin: 0px auto;
}
.divn {  
    padding:30px; 
    background:red; 
    width:1px; 
    border-radius:35px; 
    top: 0px;
    bottom: 0px;
    left: 0px;
    right: 0px;
    /*position: absolute;
    margin: auto;*/
} 
</style>
</head>
<body>
<h1>Welcome to zen module</h1>
<div class='divn'></div> 
<div class="fixed-size-square" onclick="popup();">
  <span>Past Thoughts</span>
</div>

<div class="size-square" onclick="popup();">
    <span>Present Thoughts</span>
</div>

<div class="square" onclick="popup();">
    <span>Future Thoughts</span>
</div>
<button>I've no thoughts</button>
</body>
</html>

我想为window.promptquestion提供两个函数,默认值。当我在提示符中单击OK时,一个函数应显示为OK clicked,当单击cancel按钮时,另一个函数应显示为cancel clicked。我怎么做

尝试一个window.promptquestion,默认值

下面是一个演示:

使用下面的代码

    var x = prompt("dvdvbd", "default");
if (x != null) {  //if user click ok 
    //do this
}
else {  //if user click cancel
    //do this
}
如果用户点击cancel,则提示框返回null;如果点击OK,则返回空字符串,且未输入任何内容。您只需检查提示符是否返回null

如果提示问题!=空的{ 你点击OK!;
}否则{提醒你出了什么问题?单击“确定”}对不起,该问题需要编辑,你可能需要编辑答案,然后查看这些其他答案。取消时Window.prompt将返回NULL,请检查该值。代码已修改。。。