简体   繁体   English

如何在 JavaScript 中动态从输入类型日期更新为输入类型文本字段

[英]How to update from input type date to input type text field dynamically in JavaScript

I want to create a input field with date but when user type his name for search then it also work in the same field.我想创建一个带日期输入字段,但是当用户输入他的名字进行搜索时,它也可以在同一个字段中工作。

More specifically I want make a dynamic input field with text and date input field in a search filter button in JavaScript .更具体地说,我想在JavaScript的搜索过滤器按钮中创建一个带有文本日期输入字段的动态输入字段。

Is it possible to create a field with date and later when user want to search by name then he able to search the name in same field and if he wants to search filter by date he also able to search in same field.是否可以创建一个带日期的字段,然后当用户想按名称搜索时,他可以在同一字段中搜索名称,如果他想按日期搜索过滤器,他也可以在同一字段中搜索。

If it's possible then how can I do this?如果有可能,那么我该怎么做?

You can use setAttribute(attr, value) property to change the attribute types.您可以使用setAttribute(attr, value)属性来更改属性类型。 More can be found here 更多可以在这里找到

Example using buttons:使用按钮的示例:

 function searchByName(){ document.getElementById("search").setAttribute("type","text"); } function searchByDate(){ document.getElementById("search").setAttribute("type","date"); }
 <button onclick="searchByName();">Search by name</button> <button onclick="searchByDate();">Search by date</button> <input type="date" name="search" id="search" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM