JavaScript中常用的互动方法ヽ( ̄▽ ̄)ノ
输出内容
<script type="text/javascript">
var mystr = "我是";
var mychar = "JavaScript";
document.write(mystr + mychar)
</script>
警告(alert消息对话框)
<html>
<head>
<title>$Title$</title>
<script type="text/javascript">
function rec() {
var mychar = "天冷多加衣!";
alert(mychar);
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,弹出对话框"/>
</body>
</html>
确认(confirm消息对话框)
<html>
<head>
<title>$Title$</title>
<script type="text/javascript">
function rec() {
var mymessage = confirm("我是大红红蝴蝶公主吗?");
if (mymessage == true) {
document.write("你是!");
}
else {
document.write("你不是!");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,弹出确认对话框"/>
</body>
</html>
提问(prompt消息对话框)
<html>
<head>
<title>$Title$</title>
<script type="text/javascript">
function rec() {
var score = prompt("请输入您的分数?");
if (score >= 90) {
document.write("你很棒!");
}
else if (score >= 75) {
document.write("不错吆!");
}
else if (score >= 60) {
document.write("要加油!");
}
else {
document.write("要努力了!");
}
}
</script>
</head>
<body>
<input name="button" type="button" onClick="rec()" value="点击我,对成绩做评价!"/>
</body>
</html>
打开新窗口(window.open)
<html>
<head>
<title>$Title$</title>
<script type="text/javascript">
function Wopen() {
window.open('https://www.imooc.com', '_blank', 'height=600,width=400,top=100,left=0');
}
</script>
</head>
<body>
<input name="button" type="button" onClick="Wopen()" value="点击我,打开新窗口!" / >
</body>
</html>
JavaScript中常用的互动方法ヽ( ̄▽ ̄)ノ
输出内容
<script type="t