简体   繁体   中英

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 .

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. 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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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