在 jQuery 中从 Alert 弹出窗口获取值

jqueryweb developmentobject oriented programming

要从 Alert 弹出窗口获取值,请使用 alert()。首先,使用 prompt() 输入用户的值。以下是代码 −

示例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<script>
   var value = prompt("Please enter an integer value");
   var multiplyBy10=10*value;
   alert("Result after multiplying by 10 = "+ multiplyBy10);
</script>
</body>
</html>

要运行上述程序,请保存文件名"anyName.html(index.html)",然后右键单击该文件。选择选项"使用 Live Server 打开"在 VS Code 编辑器中 −

输出

将产生以下输出 −

输入一个整数值,点击 OK 按钮。

点击 OK 按钮后,快照如下 −


相关文章