Tag Archives: js

JavaScript realizes the longest substring of non repeated characters

simple rough direct code

is easy to understand with console, the code is as follows:

    var lengthOfLongestSubstring = function (s) {
      var arr = [];
      var max = 0;
      for (let index = 0; index < s.length; index++) {
        var a = arr.indexOf(s[index]);
        console.log(a, s[index], 222)
        if (a != -1) {
          arr.splice(0, a + 1)
          console.log(111, arr, max)
        }
        arr.push(s.charAt(index))
        console.log(arr, 222)
        max = Math.max(arr.length, max)
      }
      return console.log(max, arr)

    };
    lengthOfLongestSubstring('abcdeasasas')

JS prompt cannot read property ‘style’ of undefined

"order": [[6, "asc"]],

Instead of

"order": [[0, "asc"]],

reason, only 3 columns, I chose column 6 to sort…

so there’s a sense that it’s out of bounds, so the error is

<div class="box-body">
    <table class="table table-bordered table-striped" id="mytable" role="grid" aria-describedby="user" style="width: 100%;">
        <thead>
        <tr>
            <th>名字</th>
            <th>年龄</th>
            <th>性别</th>
        </tr>
        </thead>
    </table>
</div>

<script>
    var table;

    $(function () {
        table = $('#mytable').DataTable({
            "sScrollY": $(this).height() -280,
            "serverSide": true,
            "processing": true,
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "info": true,
            "autoWidth": true,
            "order": [[0, "asc"]],//按照第几列排序
            "pageLength": 10,
            "bLengthChange": true,
            "oLanguage": lang,
            "ajax": {
                "url": "${CONTEXT_PATH}/admin/essay/voteList",
                "type": "POST",
                "dataSrc": "data",
                "data": function (d) {
                    d.extra_search = $("#form").serialize();
                }
            }, 
            "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 5 ] }],
            "columns": [
                {"data": "name"},
                {"data": "age"},
                {"data": "sex"}
            ]
        });
    });


</script>


The JSON object is converted into a formdata object, and the formdata object is converted into a JSON object

in the backward request, if there is a file object in the uploaded data, we need to use the form submission, at this time we need to convert the JSON object into a formData object, see the code

for details

  const formData = new FormData();
  Object.keys(params).forEach((key) => {
    formData.append(key, params[key]);
  });

may also require formData to be converted to JSON, the code is as follows:

  var jsonData = {};
  formData.forEach((value, key) => jsonData[key] = value);

HTML using title attribute to display text with mouse hover

mouse hover display text, HTML use title attribute can achieve the effect of text display, this attribute is more practical, the need for friends can refer to

< A href=# title=” here is the text displayed “> hello< /a>

when we hover over hello last time we will have text and here is the text that is displayed.