我什至 Java 如何编写脚本?
How Script Do I Do I Even Java?
我想做一个网站来记录你一天抽的烟量。
总体目标是帮助吸烟者通过达到自己设定的目标来减少吸烟量。
第一个重要函数是当天要吸的香烟数量。第二个是一个答题器,可以记录当天吸的香烟数量。
这是我的:
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="1">
<p>This is how many smokes you're having today</p>
<button onclick="myFunction()">SUBMIT</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
<script type="text/javascript">
var clicks = 0;
function onClick() {
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
};
</script>
<button type="button" style="height:200px;width:200px" onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p>THIS IS HOW MUCH YOU'VE SMOKED TODAY: <a id="clicks">0</a></p>
</body>
</html>
我对这类事情真的很陌生,我有很多问题
我不太确定如何提问,但我想知道如何提问
当吸烟数量超过每日目标时,使一些文本显示为 "You went over the goal!"。让我知道你们是否也有任何建议。提交文本显示为一个按钮
我将其保存为 html 文件。我什么都用记事本做。
I was wondering how to make some text appear like "You went over the
goal!" when the Number of cigarettes smoked goes over the daily goal.
你只需要在执行你的onClick
函数时检查clicks
是否大于你的目标数。
var goal = document.getElementById("myNumber").value;
if (clicks > goal) {
document.getElementById("demo").innerHTML = "You went over your goal!";
//or...
alert("You went over your goal!");
}
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="1">
<p>This is how many smokes you're having today</p>
<button onclick="myFunction()">SUBMIT</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
<script type="text/javascript">
var clicks = 0;
var surpassedDailyGoal = false;
function onClick() {
var dailyGoal = document.getElementById("myNumber").value;
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
if( clicks > dailyGoal && !surpassedDailyGoal ){
surpassedDailyGoal = true;
document.body.insertAdjacentHTML('beforeend', '<p>Stop smoking you chimney you...</p>');
}
};
</script>
<button type="button" style="height:200px;width:200px" onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p>THIS IS HOW MUCH YOU'VE SMOKED TODAY: <a id="clicks">0</a></p>
</body>
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="4">
<p>This is how many smokes you're having today</p>
<p id="demo"></p>
<button onclick="myFunction()">SUBMIT</button>
<button type="button" id='btn' onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p id='disp'>THIS IS HOW MUCH YOU'VE SMOKED TODAY:
<p id="clicks">0</p>
</p>
</body>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
document.getElementById("btn").disabled = false;
clicks = -1;
onClick();
}
var clicks = 0;
function onClick() {
clicks += 1;
if (clicks <= document.getElementById("myNumber").value) {
document.getElementById("disp").innerHTML = "THIS IS HOW MUCH YOU'VE SMOKED TODAY: ";
document.getElementById("clicks").innerHTML = clicks;
} else {
document.getElementById("clicks").innerHTML = '';
document.getElementById("btn").disabled = true;
document.getElementById("disp").innerHTML = 'You have exceeded the limit of ' + (clicks - 1) + ' cigarettes. ';
}
};
</script>
</html>
我想做一个网站来记录你一天抽的烟量。 总体目标是帮助吸烟者通过达到自己设定的目标来减少吸烟量。 第一个重要函数是当天要吸的香烟数量。第二个是一个答题器,可以记录当天吸的香烟数量。
这是我的:
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="1">
<p>This is how many smokes you're having today</p>
<button onclick="myFunction()">SUBMIT</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
<script type="text/javascript">
var clicks = 0;
function onClick() {
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
};
</script>
<button type="button" style="height:200px;width:200px" onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p>THIS IS HOW MUCH YOU'VE SMOKED TODAY: <a id="clicks">0</a></p>
</body>
</html>
我对这类事情真的很陌生,我有很多问题 我不太确定如何提问,但我想知道如何提问 当吸烟数量超过每日目标时,使一些文本显示为 "You went over the goal!"。让我知道你们是否也有任何建议。提交文本显示为一个按钮 我将其保存为 html 文件。我什么都用记事本做。
I was wondering how to make some text appear like "You went over the goal!" when the Number of cigarettes smoked goes over the daily goal.
你只需要在执行你的onClick
函数时检查clicks
是否大于你的目标数。
var goal = document.getElementById("myNumber").value;
if (clicks > goal) {
document.getElementById("demo").innerHTML = "You went over your goal!";
//or...
alert("You went over your goal!");
}
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="1">
<p>This is how many smokes you're having today</p>
<button onclick="myFunction()">SUBMIT</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
}
</script>
<script type="text/javascript">
var clicks = 0;
var surpassedDailyGoal = false;
function onClick() {
var dailyGoal = document.getElementById("myNumber").value;
clicks += 1;
document.getElementById("clicks").innerHTML = clicks;
if( clicks > dailyGoal && !surpassedDailyGoal ){
surpassedDailyGoal = true;
document.body.insertAdjacentHTML('beforeend', '<p>Stop smoking you chimney you...</p>');
}
};
</script>
<button type="button" style="height:200px;width:200px" onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p>THIS IS HOW MUCH YOU'VE SMOKED TODAY: <a id="clicks">0</a></p>
</body>
<html>
<head>
<title>SMOKERS TOOL</title>
</head>
<body>
<h3>Daily goal</h3>
<input type="number" id="myNumber" value="4">
<p>This is how many smokes you're having today</p>
<p id="demo"></p>
<button onclick="myFunction()">SUBMIT</button>
<button type="button" id='btn' onClick="onClick()">HIT ME EVERY TIME YOU SMOKE</button>
<p id='disp'>THIS IS HOW MUCH YOU'VE SMOKED TODAY:
<p id="clicks">0</p>
</p>
</body>
<script>
function myFunction() {
var x = document.getElementById("myNumber").value;
document.getElementById("demo").innerHTML = x;
document.getElementById("btn").disabled = false;
clicks = -1;
onClick();
}
var clicks = 0;
function onClick() {
clicks += 1;
if (clicks <= document.getElementById("myNumber").value) {
document.getElementById("disp").innerHTML = "THIS IS HOW MUCH YOU'VE SMOKED TODAY: ";
document.getElementById("clicks").innerHTML = clicks;
} else {
document.getElementById("clicks").innerHTML = '';
document.getElementById("btn").disabled = true;
document.getElementById("disp").innerHTML = 'You have exceeded the limit of ' + (clicks - 1) + ' cigarettes. ';
}
};
</script>
</html>