简体   繁体   中英

Changing language dynamically DateTimePicker jQuery Plugin

I want to dynamically change the language of the DateTimePicker jQuery Plug-in ( http://xdsoft.net/jqplugins/datetimepicker/ ) and I'm getting an "undefined" error for the lang1 inside the last plug-in call:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Datatimepicker</title>
<link rel="stylesheet" href="css/jquery.datetimepicker.css">
    <script src="js/jquery-2.1.1.min.js"></script>
    <script src="js/jquery.datetimepicker.js"></script>
</head>
<body>
    <input id="datetimepicker" type="text" placeholder="Datetimerpicker">
    <input id="lang" type="text" placeholder="language" value="en"><div class="select">select language</div>
    <script>
            var lang1;

        $(".select").click(function(){
        lang = $('#lang').val();
        lang1 = '"'+lang+'"';
        return lang1
        });

        $(".select").click(function(){
            console.log(lang1);
        $('#datetimepicker').datetimepicker({
            lang: lang1
        })
        });
    </script>
</body>
</html>

Shouldn't this work?

You defined two click handlers which you expect to somewhat magically exchange the lang1 variable.

Probably you intended this:

    $(".select").click(function(){
        var lang = $('#lang').val(); // 1
        console.log(lang); // 2
        $('#datetimepicker').datetimepicker({ lang: lang }); // 3
    });
  1. Get the current lang value from input field #lang
  2. Log it to the console
  3. Initialize the datepicker to use the language lang .

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