简体   繁体   中英

Store Date in localStorage

Using jquery mobile 1.3 I was able to collect and display values from some input fields using localSotorage with this function:

    <script type="text/javascript">
    function datosCliente (info) {
        localStorage.setItem(info.name,info.value);
    }
</script>

And here is a sample of one input field calling the function:

<label for="basic">Nombre:</label>
        <input type="text" name="nombre" id="basic" data-mini="true" onkeyup="datosCliente(nombre)"/>

I was hoping to do the same on an input type date:

<label for="fecha">Fecha</label>
        <input name="fecha" id="fecha" type="date" data-role="datebox" data-options='{"mode":"calbox", "useNewStyle":true}' onkeyup="datosCliente(fecha)" />

And the display the value using:

<p><span>Fecha: </span><script>document.write(localStorage.getItem("fecha"));</script></p>

But is it turns out All I get is null when I want to display the value of this field. Is it because I am using the jQueryMobile - DateBox plugin to pick the date ? Or I have to try a different approach to collect the value from this type of input ?

使用onchange而不是onkeyup是一个好主意,尤其是因为浏览器UI不会触发按键。

Not sure if this is an answer per-say, but you can try changing nombre and fecha to this . And might I add, instead of using document.write, you could use console.log , that way you can tell if it is an object as opposed to a string, etc. This would probably have gone in the comments section but I don't seem to have the privileges to do that just yet. Good luck.

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