[英]replace part of string with html tags in react
我有这个字符串“接受条款和条件”,根据设计,我需要用跨度标签替换该字符串的一部分,也就是说,“条款”和“条件”应该用跨度包装,如<span>terms</span>
和<span>conditions</span>
。 为了找到解决方案,我找到了如何使用替换为 React 中字符串的特定部分添加颜色? 但它没有按预期工作。 所以,我有这样使用的 FormInput 组件:
<FormInput
type="checkbox"
value={formik.values.terms}
name="terms"
onChange={formik.handleChange}
onBlur={formik.handleBlur}
label={`Accept terms and conditions`}
checkbox={true}
>
{formik.touched.terms && formik.errors.terms ? (
<ErrorMessage termsCheckbox={true}>
{formik.errors.terms}
</ErrorMessage>
) : null}
</FormInput>
如您所见,我正在传递 label={ Accept terms and conditions
} 并且我需要确保“条款”和“条件”这两个词是红色的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.