首页 > 解决方案 > 如何删除输入字段的内容?

问题描述

 <div className="pt-4">
              <label
                htmlFor="location"
                className="block text-sm font-semibold text-gray-700"
              >
                Refferal *
              </label>
              <div className="relative text-gray-400 focus-within:text-gray-600">
                <div className="pointer-events-none absolute inset-y-0 left-0 pl-3 flex items-center">
                  <SearchIcon className="h-5 w-5" aria-hidden="true" />
                </div>
                <input
                  id="search"
                  className="pl-10 p-2 border shadow-sm focus:ring-indigo-500 focus:border-indigo-500 focus:outline-none block w-full sm:text-sm border-gray-300 rounded-md"
                  placeholder="Search"
                  type="search"
                  name="refferal"
                  value={values.refferal || profile.refferal}
                  onChange={handleInputChange}
                />
              </div>
            </div>

我在我的反应组件中预填充了这个输入字段。虽然,我想在用户输入字段时更改字段内的数据,但是当用户尝试清空字段内的内容时。弹出预填充的数据。如何清空该字段以便用户可以相应地更新数据。?

标签: reactjsreact-nativereact-hooks

解决方案


推荐阅读