Datalist属性在Google Chrome中无效

时间:2016-04-13 09:20:02

标签: html attributes

Datalist属性在Google Chrome中不起作用,它在Firefox中运行良好

请在这里查看http://prntscr.com/arny81

提前感谢您的帮助。

HTML

<td><input onkeyup="showCustomers(this.value)" placeholder="Enter Customer Name" list="selectCust" name="Cno" />
<datalist id="selectCust">
                    </datalist>
</td>

的Javascript

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();
}
}

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 !== "") {
$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。

1 个答案:

答案 0 :(得分:0)

改为在CSS中定位ID,这应该可以正常工作。

HTML:

<datalist id="dl">
   Your content goes here
</datalist>

CSS:

#dl {
   display: block;
}

这适用于Chrome或任何其他浏览器。

相关问题