RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

rabbit's questions

Martin Hope
rabbit
Asked: 2024-06-25 09:11:44 +0000 UTC

通过按键盘键react js删除数组元素

  • 5

我有可以很好地删除当前组件的代码。请告诉我如何通过按键盘按键从数组中删除当前组件?

const [SimpleArr, setSimpleArr] = useState([])

{SimpleArr.map((_, i) => (
  <SimpleComponent key={i} id={i} Arr={SimpleArr} setArr={setSimpleArr} />
))}

SimpleComponent.jsx

export function SimpleComponent({id, Arr, setArr}) {
  return (
    <button onClick={() => {setArr(Arr.filter((_, i) => i !== id))}}>
      Remove
    </button>
  )
}

编辑

const RemoveElement = (Index, Field, setField) => {
  setField(Field.filter((_, i) => i !== Index))
}

const [SelectedElement, setSelectedElement] = useState()

const SelectedElementRemove = (event) => {
  if (event.key === "Delete" && SelectedElement != null) {
    RemoveElement(parseInt(SelectedElement, 10), SimpleComponentArr, setSimpleComponentArr)
    setSimpleComponentArr((prev) => {
      localStorage.setItem("SimpleComponentArr", JSON.stringify([...prev]))
      return [...prev];
    });
    setSelectedElement(null)
  }
}
useEffect(() => {
  document.addEventListener("keydown", SelectedElementRemove, false)
  return () => {
    document.removeEventListener("keydown", SelectedElementRemove, false)
  }
}, [SelectedElementRemove])

{SimpleComponentArr.map((_, i) => <SimpleComponent key={i} id={i} setSE={setSelectedElement} />)}

SimpleComponent.jsx

export function SimpleComponent({ id, setSE }) {
  return (
    <div onClick={event => {setSE(event.target.dataset.id)}} data-id={id}>
      Text
    </div>
  )
}
reactjs
  • 1 个回答
  • 35 Views
Martin Hope
rabbit
Asked: 2024-03-31 18:13:17 +0000 UTC

在react-pdf反应插件中生成pdf之前运行一个函数

  • 6

我使用两个插件1react-pdf来生成 pdf 和一个插件html-to-image将 html 转换为图像。但问题是转换功能只有在创建pdf后才起作用。这是函数:

const downloadImage = async () => {
  return await htmlToImage.toPng(testEl.current, {
    cacheBust: false,
  })
}

在此函数中,我返回一个 URL,并将其放入<Image />. 例如:

<Image src={downloadImage} cache={false} />

也许把函数放进去useEffect?请在这件事上给予我帮助。这是完整的代码:

import {PDFDownloadLink, Page, Text, View, Document,Image} from "@react-pdf/renderer";
import * as htmlToImage from "html-to-image";

export function CustomComponent() {
  const testEl = useRef();

  const downloadImage = async () => {
    return await htmlToImage.toPng(testEl.current, {
      cacheBust: false,
    });
  };

  const MyDoc = () => (
    <Document>
      <Page>
        <View>
          <Image src={downloadImage} cache={false} />
        </View>
      </Page>
    </Document>
  );

  return (
    <>
      <div ref={testEl} className="test">
        Text
      </div>
      <PDFDownloadLink document={<MyDoc />} fileName="print-test.pdf">
        {({ blob, url, loading, error }) =>
          loading ? "Loading document..." : "Download now!"
        }
      </PDFDownloadLink>
    </>
  );
}

编辑

const downloadImage = () => {
  return htmlToImage.toPng(testEl.current, {
    cacheBust: false,
  });
};

const MyDoc = () => {
  return (
    <Document>
      <Page>
        <View>
          <Image src={downloadImage} cache={false} />
        </View>
      </Page>
    </Document>
  );
};

const asyncF = async () => {
  await downloadImage();
  await MyDoc();
};

useEffect(() => {
  asyncF();
});

编辑2

import React, { useState, useEffect, useRef, Fragment } from "react";
import { usePDF, Page, Text, View, Document, Image } from "@react-pdf/renderer";
import * as htmlToImage from "html-to-image";

export function CustomComponent({}) {

  const downloadImage = async () => {
    return await htmlToImage.toPng(
      document.querySelector(".test"),
      { cacheBust: false }
    );
  };

  const myPdfDocument = (
    <Document>
      <Page>
        <View>
          <Image src={downloadImage} cache={false} />
        </View>
      </Page>
    </Document>
  );

  function triggerDownload(url) {
    const a = document.createElement("a");
    a.href = url;
    a.download = "test.pdf";
    a.click();
  }

  const [pdfInstance, updatePdfInstance] = usePDF({});
  const [isDownloading, setIsDownloading] = useState(false);

  function initiateDownload() {
    setIsDownloading(true);
    updatePdfInstance(myPdfDocument);
  }

  useEffect(() => {
    if (isDownloading && pdfInstance.url) {
      triggerDownload(pdfInstance.url);
      setIsDownloading(false);
    }
  }, [isDownloading, pdfInstance.url]);

  return (
    <>
      <div className="test">Text</div>
      <button onClick={initiateDownload} disabled={isDownloading}>
        {isDownloading ? "Loading..." : "Download PDF"}
      </button>
    </>
  )
}
reactjs
  • 1 个回答
  • 21 Views
Martin Hope
rabbit
Asked: 2024-03-26 03:09:14 +0000 UTC

更改对象键中键的值,就像反应中的切换一样

  • 6

我有这样的状态,有钥匙和子钥匙。我想根据切换原则将值更改true为false,反之亦然。我尝试访问我需要的密钥,如果对象中只有一个父密钥,它可以工作,但如果我有多个父密钥,它就不起作用。

告诉我在哪里修复错误?谢谢你!

const [Layers, setLayers] = useState({
   KeyParentOne: { Control: true, DropDown: false },
   KeyParentTwo: { Control: true, DropDown: false }
});

<button onClick={() => {
        setVal((prevState) => ({ KeyParentOne: { ...prevState.KeyParentOne, Control: !prevState.KeyParentOne.Control} }))}
 >
      Click
 </button>
    
 <button onClick={() => {
        setVal((prevState) => ({ KeyParentOne: { ...prevState.KeyParentOne, DropDown: !prevState.KeyParentOne.DropDown} }))}
 >
      Click
 </button>
    
 <button onClick={() => {
        setVal((prevState) => ({ KeyParentTwo: { ...prevState.KeyParentTwo, Control: !prevState.KeyParentTwo.Control} }))}
    >
      Click
 </button>
    
 <button onClick={() => {
        setVal((prevState) => ({ KeyParentTwo: { ...prevState.KeyParentTwo, DropDown: !prevState.KeyParentTwo.DropDown} }))}
 >
      Click
 </button>
reactjs
  • 1 个回答
  • 16 Views
Martin Hope
rabbit
Asked: 2024-03-22 01:57:35 +0000 UTC

在反应中向状态数组添加值时出错

  • 5

我想有条件地向数组添加一个值。这state和添加功能:

const [Selectors, setSelectors] = useState([]);
const SelectorAdd = (newValue) => {
   setSelectors((array) => [...array, newValue]);
}

我只想将任何文本值添加Selectors到此条件内的数组中:

{Yes ?
   <>
      <AnyComponent />
      {SelectorAdd('text value')} <=== ТУТ
   </>
: null}

我收到此错误:

Too many re-renders. React limits the number of renders to prevent an infinite loop.

请告诉我,这是什么错误?谢谢你!

reactjs
  • 1 个回答
  • 21 Views
Martin Hope
rabbit
Asked: 2024-02-01 01:16:15 +0000 UTC

检查具有唯一名称的键对象数组中的空键反应

  • 5

我有一个带有数组的钩子,其中包含具有唯一名称的键列表。每个键都包含一个带有对象的数组:

const [Value, setValue] = useState([
      {
        Item1: [{test1: null, test2: null}],
        Item2: [{test1: "some text", test2: "some text"}],
        Item3: [{test1: null, test2: null}],
        ...
        ItemN: [{test1: null, test2: null}]
      }
])

密钥test1和test2名称是永久的。那些。allItem将只包含这些键。事实上,Item这样的键会有很多,我需要test1检查test2每null一个Item。访问密钥时出现问题Item。

我尝试过Object.keys,但没有得到任何结果,也没有错误:

{Object.keys(Value).map((item, i) => {
  if (item.test1 !== null && item.test2 !== null) {
     return (<div key={i}>{item.test1 - item.test2}</div>)
  }
})}
reactjs
  • 1 个回答
  • 31 Views
Martin Hope
rabbit
Asked: 2024-01-31 18:48:06 +0000 UTC

从反应数组对象中获取带有键的子对象

  • 5

我有一个包含数组中的对象的钩子。该对象本身包含带有键的子对象:

const [Value, setValue] = useState([
      {
        Item1: [
          {
            SubItem11: [{test_key1: "text", test_key2: "another text"}],
            SubItem12: [{test_key1: "text", test_key2: "another text"}]
          }
        ],
        Item2: [
          {
            SubItem21: [{test_key1: "text", test_key2: "another text"}],
            SubItem22: [{test_key1: "text", test_key2: "another text"}]
          }
        ]
      }
])

请告诉我如何使用map. 另外,您能否展示一个仅访问特定对象键的示例?例如,如何仅访问SubItem12?

谢谢你!

reactjs
  • 2 个回答
  • 27 Views
Martin Hope
rabbit
Asked: 2024-01-27 16:45:10 +0000 UTC

将按钮单击状态传递给数组对象并从反应集合中禁用按钮单击

  • 5

我有一个按钮集合,我想确保当单击某个按钮时,其他集合中的类似按钮不会被单击。

例如:

<div>
 <button>A-1</button>
 <button>A-2</button>
 <button>A-3</button>
 <button>B-1</button>
 <button>B-2</button>
 <button>B-3</button>
</div>

<div>
 <button>A-1</button>
 <button>A-2</button>
 <button>A-3</button>
 <button>B-1</button>
 <button>B-2</button>
 <button>B-3</button>
</div>

当我单击一个按钮时B-3,我希望B-3除当前按钮之外的所有按钮都是这样的disabled。

例如,我单击按钮B-3,B-3除了当前的之外,所有内容都被禁用。

这实际上很容易做到,但我想将按下的按钮状态存储在数组对象的键的挂钩中。并将按下按钮的状态传递给钩子,如下所示B-*:

const [Buttons, setButtons] = useState([{ ClickedButtons: [null, null] }]);

null #1 - `A-*` кнопки
null #2 - `B-*` кнопки

我不太明白如何将按下按钮的状态输入到这个钩子中并禁用所有类似的按钮。请帮帮我。

<ClickedButtons id={1} />
<ClickedButtons id={2} />
<ClickedButtons id={3} />

<ButtonShow clickFn={btnClick} id={1} buttons={buttons} />
<ButtonShow clickFn={btnClick} id={2} buttons={buttons} />
<ButtonShow clickFn={btnClick} id={3} buttons={buttons} />
reactjs
  • 2 个回答
  • 42 Views
Martin Hope
rabbit
Asked: 2024-01-21 23:22:04 +0000 UTC

在反应中传递动态元素中的输入数据

  • 5

我有一个代码,可以在其中动态创建带有图像的组件并保存其状态。

状态存储在此数组中:

const [UploadLogos, setUploadLogos] = useState([0]);
const dynamicLogos = (id, url) => {
    setUploadLogos((el) => {
      let ArrayLogos = [...el]; 
      ArrayLogos[id] = url; 
      return ArrayLogos 
    })
};

代码按其应有的方式工作,而且在组件内部SimpleComponent有一个输入,我想在其中提供数据并保存此状态:

<input type="number" value={{}} onChange={() => {}} />

请告诉我该怎么做?谢谢你!

这是整个代码:

应用程序.js

import React, { useState } from 'react';
import { SimpleComponent } from './SimpleComponent ';

function App() {

  const [UploadLogos, setUploadLogos] = useState([0]);
  const dynamicLogos = (id, url) => {
        setUploadLogos((el) => {
          let ArrayLogos = [...el]; 
          ArrayLogos[id] = url; 
          return ArrayLogos 
        })
  };
  
  return (
    <div className="App">
      <button
        onClick={() =>
          setUploadLogos([...UploadLogos, UploadLogos.length])
        }
      >
        Add
      </button>
      {UploadLogos.map((logo, i) => (
        <SimpleComponent
          key={i}
          id={i}
          Image={logo}
          setImage={dynamicLogos}
        />
      ))}
    </div>
  );
}

export default App;

SimpleComponent.jsx

export function SimpleComponent({id, Image, setImage}) {
    return (
      <>
        <input 
            type="file" accept="image/*"
            onChange={event => { if (!event.target.files[0]) return; setImage(id, URL.createObjectURL(event.target.files[0])) }} 
        />
        <img src={Image} /> 
        <input type="number" value={{}} onChange={() => {}} />
      </>   
    )
}
reactjs
  • 1 个回答
  • 31 Views
Martin Hope
rabbit
Asked: 2024-01-21 13:35:39 +0000 UTC

在反应中点击渲染动态元素时动态 useRef 和保存状态

  • 5

我有一个功能,可以在单击按钮时添加带有文件输入的元素,并且对于每个添加的输入,我将数据填充到挂钩数组中。此外,我还使用useRef将本机输入与文件上传按钮相关联。

但我不知道如何为创建的每个输入使用文件上传。我还想保存下载文件的状态。

我想做的只是使用文件输入创建动态元素,放置图像并将该状态存储在数组中。

也许我可以在这里使用动态挂钩?

<input type="file" 
       accept="image/*" 
       style={{display: "none"}} 
       ref={logoRef} 
       onChange={event => { /* тут возможно динамический хук для сохранения состояния */(URL.createObjectURL(event.target.files[0])) }} 
/>

请告诉我该怎么做?请帮我!

这是代码:

应用程序.js

import React, { useState } from 'react';
import { SimpleComponent } from './SimpleComponent ';

function App() {

  const [UploadLogo, setUploadLogo] = useState([]);
  
  return (
    <div className="App">       
       <SimpleComponent UploadLogo={UploadLogo} setUploadLogo={setUploadLogo} /> 
    </div>
  );
}



export default App;

SimpleComponent.jsx

import React, { useState, useEffect, useRef } from 'react';

export function SimpleComponent({UploadLogo, setUploadLogo}) {
    const logoRef = useRef();
    return(

    <button onClick={() => setUploadLogo([...UploadLogo, `Logo${UploadLogo.length}`])}>
     Add
    </button>

    {UploadLogo.map((logo, i) => (
       <div key={i}>
            <input type="file" accept="image/*" style={{display: "none"}} ref={logoRef} 
             onChange={event => { /* тут возможно динамический хук для сохранения состояния */(URL.createObjectURL(event.target.files[0])) }} 
            />
            <button onClick={() => imageRef.current?.click()}>
             Upload Logo
            </button>
            <img src="{ ??? }">
        </div>
     ))}

)} 
reactjs
  • 1 个回答
  • 11 Views
Martin Hope
rabbit
Asked: 2023-12-18 14:26:24 +0000 UTC

将数据从组件传递到反应组件

  • 5

我有使用两个独立组件的反应代码。单击第一个组件中的按钮时,我隐藏当前组件并显示另一个组件。但我也想将一些值从第一个组件(从INPUTS)传递到第二个组件。请告诉我该怎么做?这是代码:

应用程序.js

import React from 'react';
import { useState } from 'react';
import { FirstSection} from './components/FirstSection';
import { SecondSection} from './components/SecondSection';

function App() {
  const [checkSection, setSection] = useState(false);
  const showSecondSection= () => setSection(true);
  
  return (
    <div className="App">
        {checkSection ? <SecondSection /> : <FirstSection onClick={showSecondSection} />}
    </div>
  );
}

export default App;

第一节.jsx

export function FirstSection({onClick}) {
    return(
        <>
         <input type="text" value="{input1}" />
         <input type="text" value="{input2}" />
         <button onClick={onClick}>Continue</button>
        </>
    )
}

第二节.jsx

export function SecondSection() {
    return(
        <>
         <p>{input1}, {input2}</p> <== Сюда я хочу передать данные из первого компонента
        </>
    )
}
javascript
  • 1 个回答
  • 25 Views
Martin Hope
rabbit
Asked: 2022-06-13 20:50:30 +0000 UTC

根据选择的单选按钮从选择中删除特定选项

  • 0

我有两个单选按钮和一个在我的网站上设置了一个选项的选项,乍一看在我看来这很容易,但我已经坐了一个半小时,无法弄清楚如何实施它。

I need to remove specific options from select depending on the selected radio button, but in such a way that when another radio button is selected, return the removed options by removing others, i.e.:

这里有两个单选按钮 -radio1和radio2, 和一个下拉菜单select- option1,option2和option3,

当我选择radio1, 然后 和 被删除option1,option2当我选择radio2, 然后option3, BUT option1和被option2返回。

remove()通过、NOT 删除是必要的display: none;,而且<select>应该只有一个 - 这就是整个困难!

请帮忙。

let options = [...document.querySelector("select").options];

document.querySelectorAll("input[name=sel]").forEach(function (current_radio) {
    current_radio.addEventListener("change", function () {
        if (current_radio.value === "one") {
        
        } else {
        
        }
    });
});
<input type="radio" name="sel" value="one" />
<input type="radio" name="sel" value="two" />

<select>
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

javascript
  • 3 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-07-11 19:39:10 +0000 UTC

使用 nth-child 构建网格框

  • 0

我有一个无法正常工作的网格 html 代码。我需要这个结果:

在此处输入图像描述

但最后,代码并没有给出想要的结果。请告诉我哪里错了。谢谢你。

.grid-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-flow:dense;
  gap: 30px;
}

.item {
  background: grey;
}

.item:nth-child(6n + 1), .item:nth-child(6n + 6) {
  grid-row:span 2;
  grid-column:span 2;
}

.item:nth-child(6n + 5) {
  grid-column:1;
}

.item:nth-child(4n) {
  grid-column: span 2;
}
<div class="grid-container">
  <div class="item">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
  <div class="item">4</div>
  <div class="item">5</div>
  <div class="item">6</div>
  <div class="item">7</div>
  <div class="item">8</div>
  <div class="item">9</div>
  <div class="item">10</div>
  <div class="item">11</div>
  <div class="item">12</div>
  <div class="item">13</div>
  <div class="item">14</div>
</div>

html
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-06-07 06:20:10 +0000 UTC

限制帖子时加载剩余帖子加载更多wordpress

  • 0

我的网站使用ajax加载帖子的原则是滚动时加载更多。可以加载,直到加载所有帖子。客户要求限制上传帖子的数量。我几乎明白了。但是有一个问题:

每个滚动条加载 8 或 9 个帖子。例如,我将上传限制为 20 个帖子。问题是代码只会加载 8 或 9 个帖子的倍数 - 16 或 18。此外,如果我限制为 30 个帖子,那么如果加载 8 个帖子,则只会加载 24 个帖子,如果加载 9 个帖子,则会加载 27 个帖子。但是如何加载其余部分,我无法理解?!那些。限制是20个,我上传8个,最后16个帖子。其他4个不会加载。

请帮助解决这个问题。或者至少给我一个提示。

谢谢!

这是ajax代码:

document.addEventListener("DOMContentLoaded", () => {
        let ajaxurl = '<?php echo admin_url('admin-ajax.php') ?>';
        let section_posts = 1;
        let postData = new FormData();
        let scroll_state = true;
        let loader = document.querySelector('.articlefeed_loader');
        let height_footer = document.querySelector('.site-footer').getBoundingClientRect().height;
        //let max_posts = <?php print json_encode(get_limit_val())?>;

        window.addEventListener('scroll', function () {
            if (scroll_state == true) {
                if ((window.innerHeight + window.pageYOffset) >= (document.body.offsetHeight - height_footer)) {
                    postData.append('action', 'loadmore');
                    postData.append('paged', section_posts);
                    postData.append('posts_per_page', <?php echo $posts_per_page;?>);
                    postData.append('cats', <?php print json_encode(get_selected_cats())?>);
                    postData.append('max_posts', <?php print json_encode(get_limit_val())?>);

                    const xhr = new XMLHttpRequest();
                    xhr.open('POST', ajaxurl);
                        xhr.addEventListener('readystatechange', function (data) {
                            if (this.readyState === 4 && this.status === 200) {
                                document.querySelector('.articlefeed_template_wrap').innerHTML += data.target.responseText;
                            } else {}
                        });            
                    xhr.send(postData);
                    scroll_state = false;
                    timeout = setTimeout(function() {
                        scroll_state = true;
                    }, 1000);
                }
            }
        });
    });

这些是 function.php 中的钩子:

函数 loadmore_get_posts(){

  $post_limit = $_POST['max_posts'];
  $paged = !empty($_POST['paged']) ? $_POST['paged'] : 1;
    $paged++;

  $args = array(
        'paged' => $paged,
        'posts_per_page' => $_POST['posts_per_page'],
        'post_type'      => 'post',
        'post_status' => 'publish',
        'cat' => $_POST['cats']
  );

  $data = new WP_Query( $args );
 
  $i = 0;
  while( $data->have_posts() && ($post_limit >= $_POST['posts_per_page']*($paged-1) + $i)) : $data->the_post();
      get_template_part( 'templates/content/templates/feeds/articlefeed_item' );
    $i++;
  endwhile;
  die;
}
add_action('wp_ajax_loadmore', 'loadmore_get_posts');
add_action('wp_ajax_nopriv_loadmore', 'loadmore_get_posts');
php
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-05-10 09:26:17 +0000 UTC

如果 str_ireplace() 不满足 php 条件

  • 0

我有一个代码,我使用以下函数将用逗号分隔的单词与文本匹配str_ireplace():

$words = "word1, word2, word3";
$text = "This is word1 text word2";

if (str_ireplace(explode(', ', $words), '', $text) != $text) {
   /*Логика*/
}

你能告诉我如何做反向逻辑吗?那些。如果没有找到或匹配。

else {}不起作用。

谢谢!

php
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-09-20 21:10:05 +0000 UTC

如果当前为空,如何用前一个正值填充?

  • 1

我有一个按以下顺序填写数字数据的表格:

Это имя поля
1
2
0
0
0
3
0
4
0
0
0
5

提示SQL如何用前面的正数填充零值?

也就是说,您需要将列变为以下形式:

Это имя поля
1
2
2
2
2
3
3
4
4
4
4
5
sql
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-08-18 04:28:37 +0000 UTC

从php数组中获取最后一个非空值

  • 1

我有一个包含 5 个元素的常规数组:

$array = array('text1','text2','text3','','');

最后两个是空的。另外,我有一个类似的数组,但空值和非空值的数量不同:

$array = array('text1','text2','text3','text4','text5');
$array = array('text1','text2','','','');

但我总是只需要从数组中获取最后一个非空元素及其在数组中的索引。数组中总是有 5 个元素——空的和非空的。

请告诉我如何使用 php 执行此操作。谢谢你。

php
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-04-14 16:38:31 +0000 UTC

触发 <input type="number"> 元素的 Sum 和 Sub 按钮的单击事件 [重复]

  • 0
这个问题已经在这里得到了回答:
触发点击箭头输入 [type="number"] 2 个答案
1 年前关闭。

我需要为<p>元素的 Sub 和 Sum 按钮定位标签<input type="number">。如果我点击#selCountSub,数字应该会增加,如果点击#selCountSum,那么数字会相应减少。

我可以编写简单的逻辑来做我想做的事。但我想知道是否有办法通过点击标签来触发元素的内部按钮<p>。

我尝试了不同的方法,但它们都不起作用。感谢您的耐心和时间。

jQuery("#selCountSub").on("click", function () {
    jQuery("input[type=number]").trigger(jQuery.Event("keydown change"));
});

jQuery("#selCountSum").on("click", function () {
    jQuery("input[type=number]").trigger(jQuery.Event("keyup change"));
});
p {
    font-size: 24px;
    cursor: pointer;
}

input[type="number"]::-webkit-inner-spin-button {
    display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<p id="selCountSub">-</p>
<input type="number" value="1" min="1" step="1" />
<p id="selCountSum">+</p>

html
  • 1 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2022-04-12 14:52:27 +0000 UTC

使用网格模板区域定位元素

  • 1

我无法使用gridgrid-template-area display创建布局模板。

我需要这样的设置:

input_1 input_1
input_2 input_3
input_4 input_4
input_5 input_5
input_6 input_7 input_8

我已经根据原理制作了类似的模板grid-template-area,并且我对网格有经验,但是我不明白为什么我的这个特殊模板不起作用。

我也尝试使用符号点 - .,但这没有帮助。

我希望输入在宽度上均匀拉伸。像这儿:

在此处输入图像描述

我知道我犯了一个小错误,也许是一个愚蠢的错误,但我找不到那个。

感谢您的耐心和时间。

form {
    display: grid;
    grid-template-areas: 'input_1 input_1' 
                         'input_2 input_3' 
                         'input_4 input_4' 
                         'input_5 input_5' 
                         'input_6 input_7 input_8';    
}

.input_1 {
    grid-area: input_1;
}

.input_2 {
    grid-area: input_2;
}

.input_3 {
    grid-area: input_3;
}

.input_4 {
    grid-area: input_4;
}

.input_5 {
    grid-area: input_5;
}

.input_6 {
    grid-area: input_6;
}

.input_7 {
    grid-area: input_7;
}

.input_8 {
    grid-area: input_8;
}
<form>
  <input class="input_1" type="text">
  <input class="input_2" type="text">
  <input class="input_3" type="text">
  <input class="input_4" type="text">
  <input class="input_5" type="text">
  <input class="input_6" type="text">
  <input class="input_7" type="text">
  <input class="input_8" type="text">
</form>

html
  • 2 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2021-12-31 19:01:04 +0000 UTC

标签内的javascript事件

  • 0

我马上问你,请不要投反对票,因为我需要关于标签内的 js 事件声明的建议。我听到了很多支持者和反对者的意见。有人说在标签内声明事件不是一个好习惯,而另一方则相反。毕竟,在标签中声明事件的后果是什么?!

像这样:

<div onlick="fname()">...</div>

优缺点都有什么?谢谢你。

javascript
  • 2 个回答
  • 10 Views
Martin Hope
rabbit
Asked: 2021-11-09 09:47:20 +0000 UTC

一个对象的多个键

  • 1

我需要将多个键与一个对象相关联。例如,我有这个代码:

var obj = {
  1 : "class1",
  2 : "class1",
  3 : "class2",
  4 : "class2",
  5 : "class3",
  6 : "class3",
  7 : "class4",
  ...
  n : "classn",
}; 

而且我需要根据索引将类分配给少数 div。我在 jquery 中这样做:

$('.container div').each(function(i) {
  $(this).addClass(obj[i]);
});

一切正常,但我会有几十个这样的 div .. 想象一下在每个 div 里面写它的索引和类,obj这有点不合理。

在上面的代码中,对象被分配给每个键。而对我来说恰恰相反。对于一个对象,一些键。像这样的东西:

var obj = {
  1, 2 : "class1",
  3, 4 : "class2",
  5, 6 : "class3",
  7, 8, 9, 10 : "class4",
  ...
  n, n2 : "classn",
};

但这不起作用,也不会。请告诉我,我该如何做这样的事情,以免为每个键产生线条。那些。我需要为一个对象分配多个键。我怎样才能做到这一点?谢谢!我非常需要它。。

javascript
  • 2 个回答
  • 10 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