Javascript jquery Select2函数中的搜索功能不工作?
代码按预期运行,但select2功能不起作用。不要得到任何错误或任何东西只是搜索选项不存在Javascript jquery Select2函数中的搜索功能不工作?,javascript,html,jquery-select2,Javascript,Html,Jquery Select2,代码按预期运行,但select2功能不起作用。不要得到任何错误或任何东西只是搜索选项不存在 <?php require 'dbConfig.php'; ?> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"&
<?php
require 'dbConfig.php';
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>[enter image description here][1]
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="32x32">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="16x16">
<link rel="manifest" href="manifest.json">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#d9230f">
<meta name="theme-color" content="#ffffff">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,700">
<link rel="stylesheet" href="css/vendor.min.css">
<link rel="stylesheet" href="css/elephant.min.css">
<link rel="stylesheet" href="css/application.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
</style>
</head>
<body style="padding: 0%;">
<div style="position: fixed; width: 100%; background-color: white; padding: 4px;"><div class="row gutter-xs" style="background-color: #029ACF;">
<div style="text-align: center; line-height: 30px;"><font style="color: #FFF;">SAMPLE TRACK (KOLKATA)</font></div>
</div>
<div class="row gutter-xs" style="margin-top: 5px;">
<button type="button" class="btn btn-info btn-xs" style="margin-left: 5px;" onclick="window.location='home.php';">HOME</button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 5px; float: right;" id="logout" onclick="window.location='logout.php';"><span class="icon icon-sign-out" style="line-height: 18px;"></span></button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 0px; float: right;" disabled="">
LOGOUT
</button>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbosale" id="cbosale" required>
<option value="">Select Sale</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1))
{
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?>/<?php echo $r1[1]; ?></option>
<?php $i1++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbogarden" id="cbogarden">
<option value="">Select Garden</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1))
{
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?></option>
<?php $i1++; } ?>
</select>
</div>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbocat" id="cbocat" required>
<option value="">Select Category</option>
<?php
$sql = "SELECT Query";
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<div id="showgrade">
<select class="custom-select custom-select-sm" name="cbograde" id="cbograde">
<option value="">Select Grade</option>
<?php
$sql = "SELECT Query"; //GradeCode CategoryCode GardenCode
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<button type="button" class="btn btn-primary" id="filter">SHOW</button>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<a class="btn btn-primary float-right" href="cmail.php">E-Mail Selected DATA</a>
<a class="btn btn-primary float-right" href="catalogue_save_exl.php">Download SELECTION</a>
</div>
</div>
</div>
<br/><br/><br/><br/><br/><br/>
<div class="row gutter-xs" style="margin-top: 155px; padding: 4px;">
<div id="showdata">
<div id="postList">
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#filter').click(function(){
var sale = $('#cbosale').val();
var cat = $('#cbocat').val();
var grade = $('#cbograde').val();
var garden = $('#cbogarden').val();
$.ajax({
type: 'POST',
url: 'catalogue_data.php',
data: 'sale='+sale+'&cat='+cat+'&grade='+grade+'&garden='+garden,
success: function(html){
$('#postList').html(html);
}
});
});
});
$(document).ready(function(){
$('#cbocat').change(function(){
var ttype = $('#cbocat').val();
$.ajax({
type: 'POST',
url: 'get_grade.php',
data: 'ttype='+ttype,
success: function(html){
$('#showgrade').html(html);
}
});
});
});
$(document).ready(function () {
$("select").select2();
});
</script>
</div>
</div>
</body>
</html>
[在此处输入图像描述][1]
样本轨道(加尔各答)
家
注销
精选销售
请尝试以下代码:
<?php
require 'dbConfig.php';
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content=" width=device-width,initial-scale=1,user-scalable=no">
<meta name="theme-color" content="#ffffff">
<title></title>[enter image description here][1]
<!-- Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="32x32">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="16x16">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#d9230f">
<!-- Manifest -->
<!-- <link rel="manifest" href="manifest.json"> -->
<!-- CSS -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,700">
<link rel="stylesheet" href="css/vendor.min.css">
<link rel="stylesheet" href="css/elephant.min.css">
<link rel="stylesheet" href="css/application.min.css">
<!-- BootStrap & Select2 CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" />
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- jQuery Mobile -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
<!-- Bootstrap & Select2 JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<!-- Script -->
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
</head>
<body style="padding: 0%;">
<div style="position: fixed; width: 100%; background-color: white; padding: 4px;">
<div class="row gutter-xs" style="background-color: #029ACF;">
<div style="text-align: center; line-height: 30px;">
<font style="color: #FFF;">SAMPLE TRACK (KOLKATA)</font>
</div>
</div>
<div class="row gutter-xs" style="margin-top: 5px;">
<button type="button" class="btn btn-info btn-xs" style="margin-left: 5px;" onclick="window.location='home.php';">
HOME
</button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 5px; float: right;" id="logout" onclick="window.location='logout.php';">
<span class="icon icon-sign-out" style="line-height: 18px;"></span>
</button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 0px; float: right;" disabled="">
LOGOUT
</button>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbosale" id="cbosale" required>
<option value="">Select Sale</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1)){
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?>/<?php echo $r1[1]; ?></option>
<?php $i1++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbogarden" id="cbogarden">
<option value="">Select Garden</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1))
{
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?></option>
<?php $i1++; } ?>
</select>
</div>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbocat" id="cbocat" required>
<option value="">Select Category</option>
<?php
$sql = "SELECT Query";
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<div id="showgrade">
<select class="custom-select custom-select-sm" name="cbograde" id="cbograde">
<option value="">Select Grade</option>
<?php
$sql = "SELECT Query"; //GradeCode CategoryCode GardenCode
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<button type="button" class="btn btn-primary" id="filter">SHOW</button>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<a class="btn btn-primary float-right" href="cmail.php">E-Mail Selected DATA</a>
<a class="btn btn-primary float-right" href="catalogue_save_exl.php">Download SELECTION</a>
</div>
</div>
</div>
<br/><br/><br/><br/><br/><br/>
<div class="row gutter-xs" style="margin-top: 155px; padding: 4px;">
<div id="showdata">
<div id="postList">
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#filter').click(function(){
var sale = $('#cbosale').val();
var cat = $('#cbocat').val();
var grade = $('#cbograde').val();
var garden = $('#cbogarden').val();
$.ajax({
type: 'POST',
url: 'catalogue_data.php',
data: 'sale='+sale+'&cat='+cat+'&grade='+grade+'&garden='+garden,
success: function(html){
$('#postList').html(html);
}
});
});
});
$(document).ready(function(){
$('#cbocat').change(function(){
var ttype = $('#cbocat').val();
$.ajax({
type: 'POST',
url: 'get_grade.php',
data: 'ttype='+ttype,
success: function(html){
$('#showgrade').html(html);
}
});
});
});
$(document).ready(function () {
$("select").select2();
});
</script>
</div>
</div>
</body>
</html>
[在此处输入图像描述][1]
样本轨道(加尔各答)
家
注销
精选销售
请尝试以下代码:
<?php
require 'dbConfig.php';
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content=" width=device-width,initial-scale=1,user-scalable=no">
<meta name="theme-color" content="#ffffff">
<title></title>[enter image description here][1]
<!-- Icons -->
<link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="32x32">
<link rel="icon" type="image/png" href="JtLogo.ico" sizes="16x16">
<link rel="mask-icon" href="safari-pinned-tab.svg" color="#d9230f">
<!-- Manifest -->
<!-- <link rel="manifest" href="manifest.json"> -->
<!-- CSS -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,700">
<link rel="stylesheet" href="css/vendor.min.css">
<link rel="stylesheet" href="css/elephant.min.css">
<link rel="stylesheet" href="css/application.min.css">
<!-- BootStrap & Select2 CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" />
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- jQuery Mobile -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
<!-- Bootstrap & Select2 JS -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<!-- Script -->
<script type="text/javascript" src="js/jquery.blockUI.js"></script>
</head>
<body style="padding: 0%;">
<div style="position: fixed; width: 100%; background-color: white; padding: 4px;">
<div class="row gutter-xs" style="background-color: #029ACF;">
<div style="text-align: center; line-height: 30px;">
<font style="color: #FFF;">SAMPLE TRACK (KOLKATA)</font>
</div>
</div>
<div class="row gutter-xs" style="margin-top: 5px;">
<button type="button" class="btn btn-info btn-xs" style="margin-left: 5px;" onclick="window.location='home.php';">
HOME
</button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 5px; float: right;" id="logout" onclick="window.location='logout.php';">
<span class="icon icon-sign-out" style="line-height: 18px;"></span>
</button>
<button type="button" class="btn btn-default btn-xs" style="margin-right: 0px; float: right;" disabled="">
LOGOUT
</button>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbosale" id="cbosale" required>
<option value="">Select Sale</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1)){
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?>/<?php echo $r1[1]; ?></option>
<?php $i1++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbogarden" id="cbogarden">
<option value="">Select Garden</option>
<?php
echo $sql1 = "SELECT Query";
$res1 = mysqli_query($db,$sql1);
$i1 = 0;
while($r1 = mysqli_fetch_array($res1))
{
?>
<option value="<?php echo $r1[0]; ?>"><?php echo $r1[0]; ?></option>
<?php $i1++; } ?>
</select>
</div>
</div>
<br>
<div class="row gutter-xs">
<div class="col-xs-6 col-md-2">
<select class="custom-select custom-select-sm" name="cbocat" id="cbocat" required>
<option value="">Select Category</option>
<?php
$sql = "SELECT Query";
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
<div class="col-xs-6 col-md-2">
<div id="showgrade">
<select class="custom-select custom-select-sm" name="cbograde" id="cbograde">
<option value="">Select Grade</option>
<?php
$sql = "SELECT Query"; //GradeCode CategoryCode GardenCode
$res = mysqli_query($db,$sql);
$i = 0;
while($r = mysqli_fetch_array($res))
{
?>
<option value="<?php echo $r[0]; ?>"><?php echo $r[0]; ?></option>
<?php $i++; } ?>
</select>
</div>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<button type="button" class="btn btn-primary" id="filter">SHOW</button>
</div>
</div>
<br/>
<div class="row gutter-xs">
<div class="col-xs-12 col-md-4">
<a class="btn btn-primary float-right" href="cmail.php">E-Mail Selected DATA</a>
<a class="btn btn-primary float-right" href="catalogue_save_exl.php">Download SELECTION</a>
</div>
</div>
</div>
<br/><br/><br/><br/><br/><br/>
<div class="row gutter-xs" style="margin-top: 155px; padding: 4px;">
<div id="showdata">
<div id="postList">
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#filter').click(function(){
var sale = $('#cbosale').val();
var cat = $('#cbocat').val();
var grade = $('#cbograde').val();
var garden = $('#cbogarden').val();
$.ajax({
type: 'POST',
url: 'catalogue_data.php',
data: 'sale='+sale+'&cat='+cat+'&grade='+grade+'&garden='+garden,
success: function(html){
$('#postList').html(html);
}
});
});
});
$(document).ready(function(){
$('#cbocat').change(function(){
var ttype = $('#cbocat').val();
$.ajax({
type: 'POST',
url: 'get_grade.php',
data: 'ttype='+ttype,
success: function(html){
$('#showgrade').html(html);
}
});
});
});
$(document).ready(function () {
$("select").select2();
});
</script>
</div>
</div>
</body>
</html>
[在此处输入图像描述][1]
样本轨道(加尔各答)
家
注销
精选销售
错误,manifest
不是rel
属性的有效值。另外,您下载的jQuery
的1.9.1、3.3.1和3.5.1版本错误,manifest
不是rel
属性的有效值。您下载的jQueryIt的1.9.1、3.3.1和3.5.1版本现在正在工作。你能指出我犯的错误吗?请不要再检查三次,把$('filter')放进去。点击(function()
,$('cbocate')。更改(function()
和`$('select')。选择2();`inside first$(document)。准备好(function())
同时移动导入引导的标签,在标签末尾选择2,你的JavaScript。这会让你的页面加载更快。但是不要改变顺序jQuery->jQuery Mobile->Bootstrap JS->Select2 JS->你的外部JS->其他标签现在正在工作。你能指出我犯的错误吗,请不要检查3次,put$(“#过滤器”)。单击(function()
,$(“#cbocate”)。更改(function()
和`$(“选择”)。选择2();`内部第一个$(文档)。准备就绪(function())
同时移动导入引导的标签,在标签末尾选择2,你的JavaScript。这会让你的页面加载更快。但是不要改变顺序jQuery->jQuery Mobile->Bootstrap JS->Select2 JS->你的外部JS->其他标签