Jquery 选择2个网页包重新编码

Jquery 选择2个网页包重新编码,jquery,npm,jquery-select2,symfony4,Jquery,Npm,Jquery Select2,Symfony4,我正在尝试在我的symphony4项目中使用select2和网页安可。 我的app.js文件已顺利加载,但在安装时未选择2。。 我不明白为什么它根本不起作用 我的html <head> {{ encore_entry_link_tags('app') }} {{ encore_entry_script_tags('app') }} </head> <body> <select> <opt

我正在尝试在我的symphony4项目中使用select2和网页安可。 我的app.js文件已顺利加载,但在安装时未选择2。。 我不明白为什么它根本不起作用

我的html

    <head>
    {{ encore_entry_link_tags('app') }}
    {{ encore_entry_script_tags('app') }}
    </head>
    <body>
    <select>
    <option value="">--Please choose an option--</option>
    <option value="dog">Dog</option>
    <option value="cat">Cat</option>
    <option value="hamster">Hamster</option>
    </select>
它看起来像什么


如果您能帮助我,我将不胜感激

您只需导入select2CSS,需要:

require('../css/app.css');
const $ = require('jquery');
console.log('Hello Webpackfdsfds Encore! Edit me in assets/js/app.js');

require('select2')
require('select2/dist/css/select2.css')
$('select').select2({ width: '100%', placeholder: "Select an Option", allowClear: true })
它还存在自定义样式,如:

  • 选择2引导主题
  • 选择2-bootstrap4-theme
  • 选择2个平面主题
  • 选择2号地铁

您可以使用Thread安装它们。

您可以尝试以下操作:导入“../../node_modules/select2/dist/css/select2.min.css”;导入“../../node_modules/select2/dist/js/select2.full.js”;谢谢你的支持。我用的是细枝,所以我不能导入任何东西。你可以在你的app.js上导入它。我用它。我做到了!我的控制台中有一条新的错误消息,预期为“无”、URL或筛选器函数,但发现“alpha(”。解析“筛选器”的值时出错。声明已删除。select2.min.css:1:2490
require('../css/app.css');
const $ = require('jquery');
console.log('Hello Webpackfdsfds Encore! Edit me in assets/js/app.js');

require('select2')
require('select2/dist/css/select2.css')
$('select').select2({ width: '100%', placeholder: "Select an Option", allowClear: true })