1 回答
TA贡献1796条经验 获得超4个赞
只需添加一个 if 块来检查值是否是苹果或橙色或其他内容,然后更新段落
<html>
<link rel="stylesheet" href="styles.css">
<title>Apple or Oranges</title>
<body>
<p id="change"> Apple or Orange?
</p>
<input type="text" id="textbox"/>
<input type="button" value="Submit" onclick="changeText()" />
<script>
function changeText() {
let lbl = document.getElementById('change');
let empName = document.getElementById('textbox').value;
if (
empName.toUpperCase() === 'APPLE' ||
empName.toUpperCase() === 'APPLES' ||
empName.toUpperCase() === 'ORANGE' ||
empName.toUpperCase() === 'ORANGES'
) {
empName += " are awesome"
}
lbl.innerText = empName;
}
</script>
</body>
</html>
- 1 回答
- 0 关注
- 98 浏览
添加回答
举报