gpt4 book ai didi

reactjs - Facebook React.js::如何创建表单输入字段并设置类型、自动对焦、必需等

转载 作者:行者123 更新时间:2023-12-02 15:26:36 25 4
gpt4 key购买 nike

我可以使用 REACTjs 创建表单输入字段,如下所示:

React.render(
React.createElement('input', null, 'Hello, text input'),
document.getElementById('example')
);

React.render(
React.createElement('textarea', null, 'Hello, textarea'),
document.getElementById('example')
);

我想要的输入字段需要类似于这样:

 <input autofocus type="text" name="name" placeholder="John Doe" required>

 <input type="url" name="website" pattern="(http|https)://.+" required>

如何使用 React.createElement( );?

我是否使用 props 对象?

最佳答案

是的,createElement (supported) attributes 使用第二个 props 参数.

所以你可以这样写:

React.createElement('input', { placeholder: 'Enter a url', type: 'url', autoFocus: true }, 'default_url'); 

关于reactjs - Facebook React.js::如何创建表单输入字段并设置类型、自动对焦、必需等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30099874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com