gpt4 book ai didi

javascript - 未设置值时删除输入

转载 作者:行者123 更新时间:2023-11-29 07:03:45 25 4
gpt4 key购买 nike

我得到了一个列表,其中 PHP 创建了 <input type="text" readonly value="' . $row[$item] . '">';来自 mySQL。有时数据库表中的字段为空,因此输入将如下所示:<input type="text" readonly value>';所以有一个值标签,但没有任何值。我尝试做的只是删除空输入。我尝试使用此代码:

function clearEmpty(){
var input = $('.plannerlist input').val();
if(input < 0){
$('.plannerlist input').remove();
}
}

.plannerlist如下列表:

<ul class="plannerlist" id="plannerlist1">
<input type="text" readonly value="Some value here">
<input type="text" readonly value>
<input type="text" readonly value="or no value like above">
<input type="text" readonly value>
</ul>

我上面写的函数根本不起作用。没有输入被删除,没有控制台错误,什么都没有......可能是什么问题?

这是我的 PHP(我知道它很乱,但它有效;)):

<?php
$host = "********";
$user = "********";
$pass = "********";
$db_name = "********";

//create connection
$connection = mysqli_connect($host, $user, $pass, $db_name);

//test if connection failed
if(mysqli_connect_errno()){
die("connection failed: "
. mysqli_connect_error()
. " (" . mysqli_connect_errno()
. ")");
}
echo '<div id="content">
<form action="save.php" method="post">
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist1">';
//get results from database
$result = mysqli_query($connection,"SELECT FR_PM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>

</section>
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist2">';
//get results from database
$result = mysqli_query($connection,"SELECT SA_AM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>
</section>
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist3">';
//get results from database
$result = mysqli_query($connection,"SELECT SA_PM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>
</section>
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist4">';
//get results from database
$result = mysqli_query($connection,"SELECT SO_AM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>
</section>
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist5">';
//get results from database
$result = mysqli_query($connection,"SELECT SO_PM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>
</section>
<section class="tabcontent">
<ul class="plannerlist" id="plannerlist6">';
//get results from database
$result = mysqli_query($connection,"SELECT MO_AM FROM anmeldungen");
$all_property = array(); //declare an array for saving property

//showing property
while ($property = mysqli_fetch_field($result)) {
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag

//showing all data
while ($row = mysqli_fetch_array($result)) {
foreach ($all_property as $item) {
echo '<input type="text" readonly value="' . $row[$item] . '">'; //get items using property value
}
}
echo '</ul>
</section>
<input name="plannersubmit" id="plannersubmit" type="submit">
</form>
</div>';

?>

最佳答案

//在你的 php foreach 中你可以这样做吗?

foreach ($all_property as $item) {
if($row[$item] != NULL || $row[$item] != '')
{
echo '<input type="text" readonly value="' . $row[$item] . '">';
}

}

关于javascript - 未设置值时删除输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42490917/

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