javascript中的url接受id的值

<script type="text/javascript" charset="utf-8">

    $(document).ready(function(){
        //传入的id  
        var id =GetRequest().id;     
          params={
            'id':id      
          }
          $.ajax({
           type: 'post',
           url: 'http://localhost:8021/app/notice/noticeDIS',
           data : params,
           dataType : 'json',
           success: function (list) {
               console.log(list);
               $("#titleId").html(list.title);
               $("#timeIDL").html("发布时间:"+myFunction(list.createTime));
               $("#timeIDR").html("发布时间:"+myFunction(list.createTime));
               $("#qua").html(list.content);
               
        
           }
          });
       });
     //获取id的值
        function GetRequest() {
          var url = location.search; // 获取url中"?"符后的字串
          var theRequest = new Object();
          if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
              theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
          }
          return theRequest;
        }
        
        /* 时间格式*/
      function myFunction(value) {
          var dateee = new Date(value).toJSON();
          var date = new Date(+new Date(dateee) + 8 * 3600 * 1000)
              .toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
          return date;
        }
      
</script>

猜你喜欢

转载自blog.csdn.net/scf1198862746/article/details/86237675
今日推荐