简体   繁体   English

在调试初学者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. 问题1.我有三个按钮,它们都影响一个文本,每个按钮应该使文本变成不同的颜色,但是不起作用。

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. 问题2。我有一个box / image元素,该元素必须受“增长”按钮和“收缩”按钮的影响,但都不起作用。

I'm extremely new to Javascript so any help is greatly appreciated!! 我是Java语言的新手,因此非常感谢您的帮助!!

$("#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. “ Boo Rules”是受3个不同按钮(分别标记为粉红色,绿色和橙色)影响的一种文本,单击该按钮可以将文本转换为该颜色。 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM