简体   繁体   English

添加 <textarea> 单击React.js上的选项后,在&lt;select&gt;标记内添加一个标记

[英]Adding <textarea> tag inside a <select> tag after clicking an option on React.js

So basically, I got the following JSX file and I want to have an event handler that listens to an event that is generated after clicking "Other" in the manufacturer section. 因此,基本上,我得到了以下JSX文件,并且我想要一个事件处理程序,该事件处理程序侦听在制造商部分中单击“其他”后生成的事件。 Please find the mentioned option as the last <option> tag inside the <select> tag with the name "colour", and inside the <Fragment> tag. 请在<select>标记内名为“ colour”的最后一个<option>标记内以及<Fragment>标记内找到上述选项。 Also, please ignore the OnClick function that is already there; 另外,请忽略已经存在的OnClick函数。 it has no use in this problem. 它在这个问题上没有用。

The event that I want to be generated is quite particular. 我想生成的事件非常特殊。 It should add a text area (or input, not entirely sure) where the "Other" option inside the drop-down menu is located so that the user is able to type the other option they didn't find in the current selection of colours. 它应该在下拉菜单内的“其他”选项所在的位置添加一个文本区域(或输入,不确定),以便用户可以键入在当前颜色选择中找不到的其他选项。

How would I be able to achieve this? 我将如何实现这一目标?

import React, { Fragment} from 'react';
import { StyledSection, StyledSectionColLeft, StyledSectionCol } from '../../../common/theme/cssStyledColumns';
import { Textarea, Select, Input, MandatoryInfo } from '../../../common/form';

const ApplianceDetails = () => (
  <Fragment>
    <h2>Appliance details</h2>
    <MandatoryInfo />
    <StyledSection>
      <StyledSectionColLeft>
        <Select name="colour" label="Colour *">
          <option value="">-Select-</option>
          <option value="Vokera">Blue</option>
          <option value="Warmflow">Red</option>
          <option value="Worcester">Yellow</option>
          <option onClick={console.log('Click happened')} value="Other">Other</option>
        </Select>
        <Input name="model" label="Model *" />
      </StyledSectionColLeft>
      <StyledSectionCol>
        <Input name="location" label="Location *" />
      </StyledSectionCol>
    </StyledSection>
  </Fragment>
);

export default ApplianceDetails;

You can set a class on an input / textarea based on the value of select . 您可以基于select的值在input / textarea上设置类。 Like this: 像这样:

<Select value={this.state.selectedOption} onChange={this.handleSelect} name="colour" label="Colour *">
  <option value="">-Select-</option>
  <option value="Vokera">Blue</option>
  <option value="Warmflow">Red</option>
  <option value="Worcester">Yellow</option>
  <option value="Other">Other</option>
</Select>

// Or textarea
<input type="text" value="" name=" className={this.state.selectedOption !== 'Other'?"hidden":""}/>

This adds a class of hidden to your input. 这为您的输入添加了一个hidden类。 Now you can use .hidden{ diplay:none; } 现在您可以使用.hidden{ diplay:none; } .hidden{ diplay:none; }

And this function will handle change of your values: 此函数将处理您的值更改:

handleSelect(evt){
  this.setState({
    selectedOption: evt.target.value
  })
}

在中使用.map<div> 标签-react.js</div><div id="text_translate"><p> 我真的很感激任何帮助。 所以该项目是一个反应项目。</p><p> 这是我获取<a href="https://i.stack.imgur.com/WelCP.png" rel="nofollow noreferrer">的内容:获取请求</a></p><p>这是我从服务器响应的内容: <a href="https://i.stack.imgur.com/e2QG3.png" rel="nofollow noreferrer">Response from server</a></p><p> 我试了一下 Postman,看看我收到的是什么类型的 json。 这是它返回的内容: <a href="https://i.stack.imgur.com/yg6IE.png" rel="nofollow noreferrer">Postman 测试</a></p><p>我遇到的问题是我无法 map 收到的数据。 一旦输入链接,我只想在首页上以一种很好的方式显示接收到的数据。</p><p> 是否可以将 map 放在 div 标签内? 或者还有另一种方法吗?</p><p> <em><strong>请注意该项目是作为功能组件编写的</strong></em></p></div> - Using .map in <div> tag - react.js

暂无
暂无

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

相关问题 在 react.js 的锚标签中添加参数 - Adding parameter in anchor tag in react.js 传递值<select>React.js 中的标签 - Pass value of <select> tag in React.js 如何将 css 应用于 textarea 标签内用逗号分隔的文本? (React.js 项目) - How do I apply css to text separated by commas inside of a textarea tag? (React.js Project) jquery-添加 <option>里面的标签<select> - jquery- Adding <option> tag inside <select> React - 在 Select 标签中使用 map 时添加默认选项 - React - Adding a default Option while using map in Select Tag react.js 中的链接标签重定向问题 - link tag redirect issue in react.js 在滚动 React.js 上更新 ID 标签 - Updating an ID tag on scroll React.js 使用react.js呈现自定义html标记 - Rendering custom html tag with react.js 如何使用 React.js 访问标签样式 - How to access to tag style with React.js 在中使用.map<div> 标签-react.js</div><div id="text_translate"><p> 我真的很感激任何帮助。 所以该项目是一个反应项目。</p><p> 这是我获取<a href="https://i.stack.imgur.com/WelCP.png" rel="nofollow noreferrer">的内容:获取请求</a></p><p>这是我从服务器响应的内容: <a href="https://i.stack.imgur.com/e2QG3.png" rel="nofollow noreferrer">Response from server</a></p><p> 我试了一下 Postman,看看我收到的是什么类型的 json。 这是它返回的内容: <a href="https://i.stack.imgur.com/yg6IE.png" rel="nofollow noreferrer">Postman 测试</a></p><p>我遇到的问题是我无法 map 收到的数据。 一旦输入链接,我只想在首页上以一种很好的方式显示接收到的数据。</p><p> 是否可以将 map 放在 div 标签内? 或者还有另一种方法吗?</p><p> <em><strong>请注意该项目是作为功能组件编写的</strong></em></p></div> - Using .map in <div> tag - react.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM