Html Datalist属性在google chrome中不起作用
Datalist属性在Google chrome中不起作用,在Firefox中可以正常工作 请看这里 提前谢谢你的帮助 HTML getCustomers.php文件Html Datalist属性在google chrome中不起作用,html,attributes,Html,Attributes,Datalist属性在Google chrome中不起作用,在Firefox中可以正常工作 请看这里 提前谢谢你的帮助 HTML getCustomers.php文件 <?php include('conn.php'); ?> <?php // get the q parameter from URL $q = $_REQUEST["q"]; // lookup all hints from array if $q is different from "" if ($q !=
<?php include('conn.php'); ?>
<?php // get the q parameter from URL
$q = $_REQUEST["q"];
// lookup all hints from array if $q is different from ""
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
$sql2 = 'SELECT Customer_Name as Cname,No from customers order by Customer_Name';
$result2 = mysqli_query($connection, $sql2) or die(mysqli_error($connection));
if (mysqli_num_rows($result2) > 0) {
?><option value=""></option><?php
// output data of each row
while($row2 = mysqli_fetch_assoc($result2)) {
if (stristr($q, substr($row2["Cname"], 0, $len))) { ?>
<option value="<?php
echo $row2['No']; ?>"><?php echo $row2["Cname"]; ?></option>
<?php } } ?>
<?php } } ?>
改为在CSS中以ID为目标,这样应该可以正常工作
HTML:
这在Chrome或任何其他浏览器中都能正常工作。您能详细说明如何在CSS中定位ID吗?事实上,我还没有编写数据列表{display:none},这是由浏览器自动完成的发布您的HTML和CSS,这样我就可以看到哪里出了问题。您好,Goncalopinto,请检查我编辑的问题。您是否尝试添加我在答案中包含的CSS?它在几个项目中对我都很有效,我昨天又试了一次(只是为了确认它在新的Chrome中可以正常工作),我在Firefox、IE和Edge中试过,所有这些都很有效。但您需要在CSS中设置,否则它将无法工作(至少在Chrome中)。
function showCustomers(str) {
if (str.length == 0) {
document.getElementById("selectCust").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("selectCust").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "getCustomers.php?q=" + str, true);
xmlhttp.send();
}
}
<?php include('conn.php'); ?>
<?php // get the q parameter from URL
$q = $_REQUEST["q"];
// lookup all hints from array if $q is different from ""
if ($q !== "") {
$q = strtolower($q);
$len=strlen($q);
$sql2 = 'SELECT Customer_Name as Cname,No from customers order by Customer_Name';
$result2 = mysqli_query($connection, $sql2) or die(mysqli_error($connection));
if (mysqli_num_rows($result2) > 0) {
?><option value=""></option><?php
// output data of each row
while($row2 = mysqli_fetch_assoc($result2)) {
if (stristr($q, substr($row2["Cname"], 0, $len))) { ?>
<option value="<?php
echo $row2['No']; ?>"><?php echo $row2["Cname"]; ?></option>
<?php } } ?>
<?php } } ?>
<datalist id="dl">
Your content goes here
</datalist>
#dl {
display: block;
}