Javascript 是否可以将此代码与不同的jQuery版本一起使用(或转换)?

Javascript 是否可以将此代码与不同的jQuery版本一起使用(或转换)?,javascript,jquery,version,Javascript,Jquery,Version,在我的项目中,我正在使用jQuery3.5.1,而这段代码不适用于该版本。 我的问题是,是否可以将此代码转换为可用于jQuery3.5.1 这可能是一个愚蠢的问题,但我对jquery还很陌生 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewpor

在我的项目中,我正在使用jQuery3.5.1,而这段代码不适用于该版本。 我的问题是,是否可以将此代码转换为可用于jQuery3.5.1 这可能是一个愚蠢的问题,但我对jquery还很陌生

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>jQuery UI Autocomplete - Multiple values</title>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
      <link rel="stylesheet" href="/resources/demos/style.css">
      <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script>
      $( function() {
        var availableTags = [
          "ActionScript",
          "AppleScript",
          "Asp",
          "BASIC",
          "C",
          "C++",
          "Clojure",
          "COBOL",
          "ColdFusion",
          "Erlang",
          "Fortran",
          "Groovy",
          "Haskell",
          "Java",
          "JavaScript",
          "Lisp",
          "Perl",
          "PHP",
          "Python",
          "Ruby",
          "Scala",
          "Scheme"
        ];
        function split( val ) {
          return val.split( /,\s*/ );
        }
        function extractLast( term ) {
          return split( term ).pop();
        }
     
        $( "#tags" )
          // don't navigate away from the field on tab when selecting an item
          .on( "keydown", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                $( this ).autocomplete( "instance" ).menu.active ) {
              event.preventDefault();
            }
          })
          .autocomplete({
            minLength: 0,
            source: function( request, response ) {
              // delegate back to autocomplete, but extract the last term
              response( $.ui.autocomplete.filter(
                availableTags, extractLast( request.term ) ) );
            },
            focus: function() {
              // prevent value inserted on focus
              return false;
            },
            select: function( event, ui ) {
              var terms = split( this.value );
              // remove the current input
              terms.pop();
              // add the selected item
              terms.push( ui.item.value );
              // add placeholder to get the comma-and-space at the end
              terms.push( "" );
              this.value = terms.join( ", " );
              return false;
            }
          });
      } );
      </script>
    </head>
    <body>
     
    <div class="ui-widget">
      <label for="tags">Tag programming languages: </label>
      <input id="tags" size="50">
    </div>
     
     
    </body>
    </html>
这个代码不是我的我是从以下地方得到的: 我使用3.5.1制作了一个JSFIDLE,向您展示它给出的错误:

索引:

<html>
<head>
    <?php
    include "includes/include.php";
    ?>
    <style>
        a {
            /* Styles for anchors without href */
            cursor:pointer;
        }
    </style>
    <title>Kenniscentrum</title>

</head>
<body>

<!--    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>-->
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

        <div class="body">

            <div class="w-75 mx-auto mt-3">

                <?php

                echo "<form method='post' id='backToMain' action=''>";
                echo "</form>";


                echo "<form method='post' id='backToSub'>";
                echo "<input type='hidden' name='rubriek' value='".$_POST['rubriek']."'>";
                echo "</form>";

                    if(isset($_POST['rubriek'] , $_POST['subrubriek'])){

                        echo "<a class='text-primary' ";
                        ?>onclick="document.getElementById('backToMain').submit();"<?php
                        echo " >Rubrieken > </a>";


                        echo "<a class='text-primary' ";
                        ?>onclick="document.getElementById('backToSub').submit();"<?php
                        echo " >Sub-Rubrieken > </a>"; echo "Artikel";

                    }
                    else if(isset($_POST['rubriek'])){
                        echo "<a class='text-primary' ";
                        ?>onclick="document.getElementById('backToMain').submit();"<?php
                        echo " >Rubrieken > </a> Sub-Rubrieken";
                    }
                    else if(!isset($_POST['subrubriek'])){
                        echo 'Rubrieken';
                    }
                ?><button class="btn btn-success float-right mr-3" data-bs-toggle="modal" data-bs-target="#modalCreate">Nieuw</button>
            </div>

            <table id="example" class="mt-3 w-75 table table-striped table-bordered mx-auto">

                <th>Naam</th>
                <?php
                    if(isset($_POST['rubriek'] , $_POST['subrubriek'])){
                        getAllArtikel();
                    }
                    else if(isset($_POST['rubriek'])){
                        getAllSubRubriek();
                    }
                    else if(!isset($_POST['subrubriek'])){
                        getAllRubriek();
                    }
                ?>

            </table>
        </div>

        <?php
        include "includes/Modals/modal.php";
        include "includes/Modals/modalEdit.php";
        include "includes/Modals/modalEditRubriek.php";
        include "includes/Modals/modalEditSubrubriek.php";
        include "includes/Modals/modalDelete.php";
        include "includes/Modals/modalDeleteRubriek.php";
        include "includes/Modals/modalDeleteSubrubriek.php";
        include "includes/Modals/modalCreate.php";
        ?>

        <script  src="includes/script.js"></script>

    </body>
</html>
包括:

    <?php
include "dbconn.php";
include "phpFunctions.php";
?>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
        crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
        integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
        integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
        crossorigin="anonymous"></script>

有些部分可能会对此感到抱歉……

正如您看到的所有jquery 3.5的工作一样,我只是使用3.5的cdn进行了更改

$function{ var availableTags=[ 动作脚本, AppleScript, Asp, 基本的 C C++, Clojure, COBOL, 冷落, 二郎, Fortran, 好极了, 哈斯克尔, JAVA JavaScript, 口齿不清, Perl, PHP, python 红宝石 斯卡拉, 计划 ]; 函数分割值{ 返回val.split/,\s*/; } 上学期的函数{ 返回分割项.pop; } $tags //选择项目时不要离开选项卡上的字段 .按下键时,功能事件{ 如果event.keyCode==$.ui.keyCode.TAB&& $this.autocomplete instance.menu.active{ 违约事件; } } .自动完成{ 最小长度:0, 来源:函数请求、响应{ //委托回自动完成,但提取最后一项 响应$.ui.autocomplete.filter availableTags,extractLast request.term; }, 重点:功能{ //防止在焦点上插入值 返回false; }, 选择:功能事件,用户界面{ var术语=拆分此值; //删除当前输入 terms.pop; //添加所选项目 terms.push ui.item.value; //添加占位符以在末尾获得逗号和空格 术语.推送; this.value=terms.join; 返回false; } }; } ; jQuery UI自动完成-多个值 标记编程语言:
是的possible@SimoneRossaini如何做到这一点?很简单,你需要看看哪个错误或不推荐的函数有你的代码和新代码。@SimoneRossaini它说:Uncaught TypeError:$..on…..autocomplete不是一个函数,我知道它可以工作,但你到底做了什么?正如你可以看到的,所有使用jquery 3.5的功能,我只是将code.jquery.com/jquery-1.12.4.js>更改为我编写的3.5版本的cdn,我知道但是3.5版本的cdn是什么?这是一个不同的版本吗?唯一的区别是它在服务器上。好的,谢谢,我仍然有一个问题,包括在我的项目中,但我会尝试解决这个问题。