我在我的项目上使用Twitter TypeAhead插件,我想修改我的脚本以正确填充输入文本。我发现了类似的问题,但不幸的是,我没有得到解决这个问题的正确方法:
根据上面的描述和参考,我创建了一个html页面,显示我的疑问:http://testsitex2019.000webhostapp.com/
首先,我将显示调用(产品)的MySql表,其中包含填充到输入文本中的记录:
id | categoryFK (Foreing Key) | ProductName | image
--------------------------------------------------------
01 | 1 (Shoes) | Adidas Shoes | img_01
02 | 1 (Shoes) | Nike Shoes | img_02
03 | 1 (Shoes) | Red Tenis | img_03
04 | 2 (Clothes) | Black Jacket | img_04
05 | 2 (Clothes) | Blu T-shirt | img_05
现在,我将显示显示的html代码:
用 php 代码填充的选择框 (#category);
使用 TypeAhead 插件填充的输入文本(#products);
以及一个 div (#image),当用户在输入文本中选择一个选项时显示一个值(#products)。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<!-- CSS library -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>
</head>
<body>
<div class="container" style="max-width:1230px;">
<h1>DYNAMIC BOOTSTRAP TWITTER TYPEAHEAD</h1>
<hr>
<br>
<div class="row">
<?php
// Include the database config file
include_once 'dbConfig.php';
// Fetch all the category data
$query = "SELECT * FROM categories ORDER BY category ASC";
$result = $db->query($query);
?>
慕工程0101907