RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-592850

Terra's questions

Martin Hope
Terra
Asked: 2024-11-01 13:06:58 +0000 UTC

如何更改反应对象中的布尔逻辑

  • 5
const [data, setData] = useState(AccordionData)

const AccordionItems = data.map((item) => {

    const OpenClose = (id) => {

        if (id === item.id) {
            setData(data => ([{
                ...data,
                open: true
            }]))

        } else {
            setData(data => ([{
                ...data,
                open: false
            }]))
        }
    }

    return <AccordionItem 
    item={item} 
    key={item.id} 
    OpenClose={OpenClose} 
    id={item.id}
    open={item.open}
    />
})

当我运行该函数时,所有元素都会重置,只有一个元素保留为无文本

javascript
  • 1 个回答
  • 37 Views
Martin Hope
Terra
Asked: 2024-10-24 20:38:18 +0000 UTC

如何更改列表中的特定元素而不在反应中创建单独的组件?

  • 5
import { useState } from "react"
import "./HiddenText.css"

const TextList = [
    {textStart: "Twenty-five hours had passed since the incident. It seemed to be a lot longer than that.", 
    textEnd: " That twenty-five hours seemed more like a week in her mind. The fact that she still was having trouble comprehending exactly what took place wasn't helping the matter. She thought if she could just get a little rest the entire incident might make a little more sense.",
    threeDots: "...",  
    key: 1},

    {textStart: "Another productive way to use this tool to begin a daily writing routine.", 
    textEnd: " One way is to generate a random paragraph with the intention to try to rewrite it while still keeping the original meaning. The purpose here is to just get the writing started so that when the writer goes onto their day's writing projects, words are already flowing from their fingers.",
    threeDots: "...",   
    key: 2},

    {textStart: "Another productive way to use this tool to begin a daily writing routine.", 
    textEnd: " One way is to generate a random paragraph with the intention to try to rewrite it while still keeping the original meaning. The purpose here is to just get the writing started so that when the writer goes onto their day's writing projects, words are already flowing from their fingers.",
    threeDots: "...",   
    key: 3},

    {textStart: "Another productive way to use this tool to begin a daily writing routine.", 
    textEnd: " One way is to generate a random paragraph with the intention to try to rewrite it while still keeping the original meaning. The purpose here is to just get the writing started so that when the writer goes onto their day's writing projects, words are already flowing from their fingers.",
    threeDots: "...",   
    key: 4},


]

export default function HiddenText() {
    const [toggleText, setToggleText] = useState(false)
    const [toggleThreeDots, setThreeDots] = useState(true)
    const [textBtn, setTextBtn] = useState("показать дополнительно")

    function openText() {
        setToggleText(toggleText => !toggleText)
        setThreeDots(toggleThreeDots => !toggleThreeDots)
        
        if (textBtn === "показать дополнительно") {
            setTextBtn("скрыть")
        } else {
            setTextBtn("показать дополнительно")
        }
    }
    
    return(
        <div className="HiddenTextContainer">
            {
                TextList.map(item => {
                    return(
                        <div className="elemCartText" key={item.key}>
                            <p>

                                {item.textStart}
 
                                {toggleThreeDots && <span>
                                    {item.threeDots}
                                </span>}

                                {toggleText && <span>
                                    {item.textEnd}
                                </span>}

                            </p>

                            <button onClick={openText}>
                                 {textBtn}
                            </button>
                        </div>

                    )
                })
            }
        </div>
    )
}
javascript
  • 1 个回答
  • 18 Views
Martin Hope
Terra
Asked: 2024-09-23 22:03:08 +0000 UTC

如何在 localStorage 中保存任务(ToDo)

  • 5

如何将任务保存在 localStorage 中,以便它们在页面重新加载后不会消失?

const contant__form = document.querySelector('.contant__form');
const container__task = document.querySelector('.container__task');


contant__form.addEventListener('submit',  addTask);
container__task.addEventListener('click', delTask);


function addTask(e) {
    e.preventDefault()
    const input = document.querySelector('.contant__form-input');

    if (!input.value == "") {
        
        const Html =`<div class="task">
                        <h1>${input.value}</h1>

                        <div class="btn__task">
                            <div class="container__del-task" data-action="del">
                                 <span class="container__del-btn"></span>
                            </div>
                        </div>
                    </div>`;

        container__task.innerHTML += Html
        
        input.value = "";
        input.focus();
    };
};



function delTask(e) {
    self = e.target;

    if (self.classList.contains('container__del-task')) {
        const parentTask = e.target.closest('.task');
        parentTask.remove();
    };

    
};
.ToDo{
    background-color: #485268;
    padding-top: 50px;
    padding-bottom: 20px;
    height: 100%;
}

.container{
    max-width: 1000px;
    margin: 0 auto;
    padding: 10px 15px;
}

.grid{
    display: grid;
    grid-template-columns: minmax(300px, 600px) 1fr;

    gap: 20px;

    align-items: center;
}

@media (max-width: 880px) {
    .grid{
        display: grid;
        grid-template-columns: minmax(100px, 900px);
    
        gap: 20px;
    
        align-items: center;
    }
    
}

.container__task{
    background-color: #626f8b;

    border-radius: 5px;
    padding: 10px 15px;
}

.task{
    display: flex;
    justify-content: space-between;
    align-items: center;

    background-color: #7c8db3;

    padding: 10px 15px;
    margin: 10px 0px;

    border: 1px solid black;
    border-radius: 10px;

    overflow: hidden;
}

.task h1{
    font-size: 1.2rem;

}


.btn__task{
    display: flex;
    justify-content: center;
}



.container__del-task{
    width: 50px;
    height: 50px;
    
    background-color: #90a4d1;
    border: 1px solid black;

    border-radius: 5px;
}

.container__del-task:hover{

    background-color: #6f91e0;
}

.container__del-task{
    position: relative;
}

.container__del-btn::after{
    content: "";
    position: absolute;

    top: 25px;
    left: 5px;

    transform: rotate(50deg);
    
    width: 40px;
    height: 2px;

    background-color: black;
}

.container__del-btn::before{
    content: "";
    position: absolute;

    top: 25px;
    left: 5px;

    transform: rotate(-50deg);
    
    width: 40px;
    height: 2px;

    background-color: black;
}

.contant__form{
    display: flex;
    flex-direction: column;

    justify-content: center;

    max-width: 500px;
    background-color: #626f8b;

    border-radius: 5px;

    padding: 10px 5px;

    
}

.contant__form-input{
    padding: 10px;
    margin: 10px;

    width: 300px;
    border-radius: 10px;

    background-color: #90a4d1;

    font-size: 1.1rem;

}

.contant__form-btn{
    display: flex;


    padding: 10px;
    margin: 10px;

    width: 320px;
    border-radius: 10px;

    background-color: #90a4d1;

    font-size: 1.1rem;
    
}
<section class="ToDo">
        <div class="container">
            <div class="grid">
                <div class="container__task">

                </div>

                <form class="contant__form">
                    <input type="text" class="contant__form-input" placeholder="Введите задачу">
                    <button class="contant__form-btn">Отправить</button>
                </form>
            </div>
        </div>
    </section>`

javascript
  • 1 个回答
  • 58 Views
Martin Hope
Terra
Asked: 2024-05-31 23:47:41 +0000 UTC

如何取消js中的函数,使li_btn再次消失,并且在不重新加载页面的情况下重复此操作

  • 6

var btn = document.querySelector('.btn');
var li_btn = document.querySelector('.li_btn');

btn.addEventListener('click', function() {
  li_btn.style.display = 'inline-flex'
});
<nav class="menu_links">
  <div class="sun">
    <i class="fa-sharp fa-solid fa-sun"></i>
  </div>
  <ul class="li_btn">
    <li><a href="#">главная</a></li>
    <li><a href="#">практика js</a></li>
  </ul>
  <div class="btn">
    <i class="fa-solid fa-bars"></i>
  </div>
</nav>

****

这张图中,代码已经写好了,就是点击有3条条纹的按钮,就会出现导航菜单。

如何让再次按下菜单时菜单再次消失?

javascript
  • 1 个回答
  • 30 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5