Hướng dẫn react-bootstrap select - chọn react-bootstrap

Lựa chọn

Tùy chỉnh người gốc với CSS tùy chỉnh thay đổi sự xuất hiện ban đầu của phần tử.

Show

Nội dung chính ShowShow

  • Lựa chọn
  • Mặc định
  • Kích thước
  • Nhận chọn giá trị phần tử bằng cách sử dụng ref
  • Để có được tham chiếu của phần tử, chúng tôi sử dụng 1import React, { Component } from "react"; 2import { Form } from "react-bootstrap"; 3 4class SimpleSelect extends Component { 5 onChangeColor() { 6 console.log(event.target.value); 7 } 8 9 render() { 10 return ( 11 12 Simple select element of react-bootstrap 13 14 Select any color : 15 20 Red 21 Blue 22 Green 23 Black 24 Orange 25 26 27 ); 28 } 29} 30 31export default SimpleSelect;4 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
  • Sử dụng phần tử chọn
  • Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.
  • Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.
  • Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.

Mặc định

Kích thước

Nhận chọn giá trị phần tử bằng cách sử dụng ref

Để có được tham chiếu của phần tử, chúng tôi sử dụng 1import React, { Component } from "react"; 2import { Form } from "react-bootstrap"; 3 4class SimpleSelect extends Component { 5 onChangeColor() { 6 console.log(event.target.value); 7 } 8 9 render() { 10 return ( 11 12 Simple select element of react-bootstrap 13 14 Select any color : 15 20 Red 21 Blue 22 Green 23 Black 24 Orange 25 26 27 ); 28 } 29} 30 31export default SimpleSelect;4 và giá trị của nó có thể được truy cập trong các thành phần hiện có.

Sử dụng phần tử chọnCopy import code for the Form component
Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.Mặc địnhKích thước
Nhận chọn giá trị phần tử bằng cách sử dụng ref

boolean

Để có được tham chiếu của phần tử, chúng tôi sử dụng 1import React, { Component } from "react"; 2import { Form } from "react-bootstrap"; 3 4class SimpleSelect extends Component { 5 onChangeColor() { 6 console.log(event.target.value); 7 } 8 9 render() { 10 return ( 11 12 Simple select element of react-bootstrap 13 14 Select any color : 15 20 Red 21 Blue 22 Green 23 Black 24 Orange 25 26 27 ); 28 } 29} 30 31export default SimpleSelect;4 và giá trị của nó có thể được truy cập trong các thành phần hiện có.

Sử dụng phần tử chọn

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.

Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.

Bạn cũng có thể chọn từ các lựa chọn tùy chỉnh nhỏ và lớn để phù hợp với các đầu vào văn bản có kích thước tương tự của chúng tôi.

boolean

API

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
1Copy Mã nhập cho thành phần biểu mẫuCopy import code for the Form component

Tên

boolean

API

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
1Copy Mã nhập cho thành phần biểu mẫuCopy import code for the Form component

Tên

function

Loại hình

Bạn cũng có thể chọn từ các lựa chọn tùy chỉnh nhỏ và lớn để phù hợp với các đầu vào văn bản có kích thước tương tự của chúng tôi.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
1Copy Mã nhập cho thành phần biểu mẫu |

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
6

Sự mô tả
Vô hiệu hóa

Làm cho điều khiển bị tắt

htmlsize

con số

Thuộc tính kích thước của phần tử HTML bên dưới. Chỉ định số lượng tùy chọn có thể nhìn thấy.

không có hiệu lực |

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
2

Thêm các kiểu xác thực "không hợp lệ" vào nhãn điều khiển và đi kèm This is an escape hatch for working with heavily customized bootstrap css.

5

isvalid
Learn more.

Thêm các kiểu xác thực "hợp lệ" vào điều khiển

const [type, setType]: any = useState('');
render(

     Select Norm Type
     
        
        
        
     value={type}
     onChange={(e: any) => setText(e.target.value)}
     
 
);

onchange

Hướng dẫn react-bootstrap select - chọn react-bootstrap

Một cuộc gọi lại bị bắn khi

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
4 prop thay đổi

kích thước15 gold badges108 silver badges148 bronze badges

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
5 |
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
6 May 17, 2020 at 20:14

Biến thể kích thướcThis is an escape hatch for working with heavily customized bootstrap css.George Francis

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.Learn more.2 gold badges6 silver badges15 bronze badges

Tôi có một thành phần biểu mẫu phản ứng bootstrap, trong đó tôi muốn nhận được giá trị của một điều khiển biểu mẫu chọn. Tôi đã cố gắng cập nhật giá trị của một móc của tôi với một onchange, nhưng dường như tôi không thể làm cho nó hoạt động (nhập luôn luôn là một chuỗi trống), mã hiện tại của tôi như sau.

Các cách tiếp cận tương tự đã làm việc với các điều khiển biểu mẫu khác, nhưng có lẽ có một cái gì đó khác nhau về Chọn.

Isherwood

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      

54,8K15 Huy hiệu vàng108 Huy hiệu bạc148 Huy hiệu đồng15 gold badges108 silver badges148 bronze badgesMay 18, 2020 at 3:58

0

Nhận chọn giá trị phần tử bằng cách sử dụng ref

Để có được tham chiếu của phần tử, chúng tôi sử dụng 1import React, { Component } from "react"; 2import { Form } from "react-bootstrap"; 3 4class SimpleSelect extends Component { 5 onChangeColor() { 6 console.log(event.target.value); 7 } 8 9 render() { 10 return ( 11 12 Simple select element of react-bootstrap 13 14 Select any color : 15 20 Red 21 Blue 22 Green 23 Black 24 Orange 25 26 27 ); 28 } 29} 30 31export default SimpleSelect;4 và giá trị của nó có thể được truy cập trong các thành phần hiện có.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7 và bây giờ chúng tôi cũng sẽ nhận được giá trị cập nhật bằng cách sử dụng
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04.

Sử dụng phần tử chọn

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.

Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.

Bạn cũng có thể chọn từ các lựa chọn tùy chỉnh nhỏ và lớn để phù hợp với các đầu vào văn bản có kích thước tương tự của chúng tôi.

API
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
and form elements. HTML doesn't allow changing components directly, but it's possible using the event handler. One-way data binding sends the value, and then HTML can be rendered inside the DOM.

Sử dụng phần tử chọn

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.

Nhưng phần quan trọng là truy cập tùy chọn đã chọn từ phần tử chọn.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
0

Bạn cũng có thể chọn từ các lựa chọn tùy chỉnh nhỏ và lớn để phù hợp với các đầu vào văn bản có kích thước tương tự của chúng tôi.

API

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05 làm loại chọn, như được hiển thị bên dưới.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05 tag as a type of select, as shown below.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
0
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05
tag as a type of select, as shown below.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
0

JSX

Trong ví dụ trên, các điều khiển biểu mẫu được tạo bằng thẻ

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05 làm loại chọn, như được hiển thị bên dưới.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7, which is used to get the updated value of the select element.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7
, which is used to get the updated value of the select element.

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
4

JSX

Trong ví dụ trên, các điều khiển biểu mẫu được tạo bằng thẻ

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05 làm loại chọn, như được hiển thị bên dưới.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7, which is used to get the updated value of the select element.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
07
, you can further process the value for different purposes, such as submitting the value to the database.

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
4

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05 làm loại chọn, như được hiển thị bên dưới.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
07, you can further process the value for different purposes, such as submitting the value to the database.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
as well.

Cùng với phần tử chọn, có một thuộc tính được thêm vào được đính kèm có tên Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > Dictamen Constancia Complemento 7, được sử dụng để nhận giá trị cập nhật của phần tử chọn.

Vì vậy, có thể có quyền truy cập vào giá trị được cập nhật sau khi giá trị của nó thay đổi, như được hiển thị bên dưới.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
, and its value can be accessed throughout the existing components.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7 event, and now we will get the updated value using
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 as well.

Để có được tham chiếu của phần tử, chúng tôi sử dụng
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
in the React component.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
3

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
property.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
6

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04
along with the select element followed by the name of reference you created before.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 trong thành phần React.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 in the React component.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
3

Bây giờ, bước tiếp theo là triển khai phần tử chọn phản ứng Bootstrap với thuộc tính

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 trong thành phần React.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 in the React component.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
3

Bây giờ, bước tiếp theo là triển khai phần tử chọn phản ứng Bootstrap với thuộc tính

Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 04 được thêm vào. Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 04 property. Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 6

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 được thêm vào.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 along with the select element followed by the name of reference you created before.

Có thuộc tính được thêm vào

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 cùng với phần tử chọn theo sau là tên tham chiếu bạn đã tạo trước đó.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
0

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
4

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
05
, that can be used to submit the form once a user clicks on the submit button.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
7

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
06
, can be used to listen for the change event of the select element, as shown below.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
0

JSX

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 và giá trị của nó có thể được truy cập trong các thành phần hiện có.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04, and its value can be accessed throughout the existing components.

Bước đầu tiên là tạo
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
07
value sends the data to the database for processing.

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 trong thành phần React.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 in the React component.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
3

Bây giờ, bước tiếp theo là triển khai phần tử chọn phản ứng Bootstrap với thuộc tính

Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 04 được thêm vào. Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 04 property. Select Norm Type { console.log("e.target.value", e.target.value); setType(e.target.value); }} > 6

    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 được thêm vào.
    
        Select Norm Type
         {
            console.log("e.target.value", e.target.value);
            setType(e.target.value);
          }}
        >
          
          
          
        
      
04 along with the select element followed by the name of reference you created before.

Có thuộc tính được thêm vào