javascript - Need help in debugging a beginners javascript code
问题描述
Problem 1. I have three buttons that all affect one text and each button is supposed to make the text turn a different color but its not working.
Problem 2. I have a box/image element that has to be affected by a grow button and shrink button but isn't working either.
I'm extremely new to Javascript so any help is greatly appreciated!!
$("#pinkButton").on("click", function() {
var booRules = console.log('booRules')
$("#funText").css("color", "pink")
})
$("#textPink").on("click", function() {
$("#funText").css("color", pink)
})
$("#textOrange").on("click", function() {
$("#funText").css("color", "orange")
})
$("#textGreen").on("click", function() {
$("#funText").css("color", "green")
})
$("#boxGrow").on(click, function() {
$("#box").animate({height:"+=35px",
width:"+=35px"}, "fast");
})
$("#boxShrink").on(click, function() {
$("#box").animate({height:"-=35px", width:"-=35px"}, "fast");
})
"Boo Rules" is the one text affected by 3 different buttons labeled Pink, Green & Orange that when clicked are supposed to turn the text into that color. Second is an image/box that when you click the Grow button its grows, shrink button it shrinks.
解决方案
Based on previous comments I have prepared the following code:
Let me know if it helps
$("#pinkButton").on("click", function() {
$("#funText").css("color", "pink")
})
$("#textPink").on("click", function() {
$("#funText").css("color", "pink")
})
$("#textOrange").on("click", function() {
$("#funText").css("color", "orange")
})
$("#textGreen").on("click", function() {
$("#funText").css("color", "green")
})
$("#boxGrow").on("click", function() {
$("#box").animate({
height: "+=35px",
width: "+=35px"
}, "fast");
})
$("#boxShrink").on("click", function() {
$("#box").animate({
height: "-=35px",
width: "-=35px"
}, "fast");
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="textPink">Pink</button>
<button id="textOrange">Orange</button>
<button id="textGreen">Green</button>
<input id="funText" type="text" value="test" />
<button id="boxGrow">Grow</button>
<button id="boxShrink">Shrink</button>
<div id="box" style="width:20px; height:20px; background-color:red"></div>
推荐阅读
- python - Python绕过/忽略else语句
- python - Python-Sqlite3:文件名、目录名或卷标语法不正确
- groovy - Groovy 字符串拆分正则表达式无法正常工作
- reactjs - 在一行中渲染网格项目 - ReactJS 和 Material-UI
- c - List *next 指针未指向另一个节点,返回 3221226356
- flutter - Flutter google map 如何在 GoogleMap 的小部件 onCreated 函数之外实例化 GoogleMapController 以进行测试?
- python - pylatex:如何更改文档的字体大小?
- swift - 加速度计数据从十六进制到浮点数
- javascript - 从 Vue 方法更新 FabricJS 对象
- python-3.x - 为什么我的不和谐机器人一次发送多条消息?