作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要动态插入一个数组(=> inputClasses) String (=> 'Invalid'),它实际上是CSS中的一个类。然后从HTML标签中将它们两个一起读取。问题是他两个都不给我。我的错误是什么?
import React from 'react';
import './Input.css';
const input = (props) => {
let inputElement = null;
const inputClasses = ['InputElement'];
if (props.invalid) {
inputClasses.push('Invalid');
}
switch (props.elementType) {
case ('input'):
inputElement = <input
className={inputClasses.join()} <---------- Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
break;
case ('textarea'):
inputElement = <textarea
className={inputClasses.join()} <---------- And Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
break;
case ('select'):
inputElement = (
<select
className={inputClasses.join()} <---------- And Here he does not give me both
defaultValue={props.value}
onChange={props.changed}>
{props.elementConfig.options.map(option => (
<option key={option.value} defaultValue={option.value}>
{option.displayValue}
</option>
))}
</select>
);
break;
default:
inputElement = <input
className={inputClasses.join()} <---------- And Here he does not give me both
{...props.elementConfig}
defaultValue={props.value}
onChange={props.changed} />;
}
return (
<div className="Input">
<label className="Label">{props.label}</label>
{inputElement}
</div>
);
};
export default input;
我很感激每一个答案!谢谢
最佳答案
类名之间必须有空格,而不是逗号
inputClasses.join(' ')
关于javascript - 如何向数组添加动态变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59917305/
我是一名优秀的程序员,十分优秀!