问题:如何避免在(document.write)中出现(null)

时间:2019-09-12 19:45:23

标签: javascript html prompt

如何更改我的代码,以便如果用户按下“取消”,则以下代码将写入document.write("#DELETE")或只是留出空白?

<!DOCTYPE html>
<html>
<body>
<script language="JavaScript">
var a = prompt("Put a text");

if (a === null || !a) {
    document.write("");
} else {
   document.write( "Your Text is: " + a );
}
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

var radiuuss = prompt("Please set the radius");
document.write("Press 1 to put the code or press 2 to clear section");   
if (radiuuss === null) {
    document.write("#DELETE");
} else {
   // document write a message with the value of the radiuuss.
}
相关问题