尝试解析javascript中的值

时间:2019-01-24 02:36:40

标签: javascript html laravel

我想解析该值,但出现错误

我想要这样的网址:

http://192.168.11.213:8080/jadwaldokter-v04-0.0.1/Jadwal/JadwalDokterDenganTanggalDokter/2019-01-08/dan/17

但是我尝试过并得到这样的东西:

http://192.168.11.213:8080/jadwaldokter-v04-0.0.1/Jadwal/JadwalDokterDenganTanggalDokter/[object%20HTMLLabelElement]/dan/17

我尝试使用此代码:

// var label = $(this).attr("data");
// var label = document.getElementById("data").value = ""+data;

这是我的刀片视图:

<html>
<head><title></title></head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://unpkg.com/gijgo@1.9.11/js/gijgo.min.js"     type="text/javascript"></script>
<link href="https://unpkg.com/gijgo@1.9.11/css/gijgo.min.css" rel="stylesheet" type="text/css" />
<body>
<ul></ul>

<label id="data" name="data" style="display: none;"></label>

    <input type="text" id="datepicker" name="datepicker" value="Date"/>     <br>
    <script>
        $('#datepicker').datepicker({
        format : 'yyyy-mm-dd'
        });
    </script>

<button>test</button>
<script src="js/test.js" type="text/javascript"></script>
</body>
</html>

这是我的js:

$("button").click( function() {
    // var label = $(this).attr("data");
    // var label = document.getElementById("data").value = ""+data;
    var test = data;
    var label  = JSON.stringify(test);

    //i want get url like this
    //http://192.168.11.213:8080/jadwaldokter-v04-0.0.1/Jadwal/JadwalDokterDenganTanggalDokter/2019-01-08/dan/17
    $.getJSON( "http://192.168.11.213:8080/jadwaldokter-v04-0.0.1/Jadwal/JadwalDokterDenganTanggalDokter/"+label+"/dan/17", function(obj) { 
    $.each(obj, function(key, value) { 
            $("ul").append(value.hariPraktek);
     });
   });
});

有人可以帮助我吗? :(

非常感谢有人帮助我:)

1 个答案:

答案 0 :(得分:0)

您真正想要的是使用var label = $('#datepicker').datepicker('getDate');

的datepicker值