gpt4 book ai didi

javascript - 根据输入数据,如果条件为真,则显示按钮

转载 作者:行者123 更新时间:2023-11-29 04:34:10 25 4
gpt4 key购买 nike

我有一个输入文本字段,我使用 javascript 和 php 从数据库中获取数据。get.html通过javascript获取数据

    function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","get.php?q="+str,true);
xmlhttp.send();
}
}

<input type="text" id="name" onblur="showUser(this.value)">
<input type="buton" name="">
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>

get.php连接数据库显示数据

<?php
$q = intval($_GET['q']);

$con=mysql_connect("localhost","root","") or die("Could not Connect with Sql");
mysql_select_db("dialog",$con) or die("Could connect to Database");
$sql="SELECT * FROM customer WHERE cx_number = '".$q."'";
$result = mysql_query($sql);

echo "<table>
<tr>
<th>cx_number</th>
<th>package</th>
<th>balance</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['cx_number'] . "</td>";
echo "<td>" . $row['package'] . "</td>";
echo "<td>" . $row['balance'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>

现在我的问题是如果包裹余额为零,如何显示增加包裹数量的按钮

最佳答案

如果每个用户都需要它,只需在 get.php 中替换

echo "<td>" . $row['balance'] . "</td>";

echo "<td>" . $row['balance'] ; 
if ($row['balance'] <= 0) echo "<button>Your button </button>";
echo "</td>";

您也可以在浏览器端执行此操作。在

之后添加
document.getElementById("txtHint").innerHTML = this.responseText;

这样的代码

$("#txtHint tr").each(function() { // cicle through each row
el=$this.find( "td:eq(2)" ) // get td with index==2.(firs==0, secon==1)...
if (parseFloat(el.html()<=0) { // check if it's 0 or lower
el.append( $( "Your button or link html here" ) ); // add button
}
});

关于javascript - 根据输入数据,如果条件为真,则显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48744854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com