我得到一个列表,其中PHP从mySQL创建<input type="text" readonly value="' . $row[$item] . '">';
。有时数据库表中的字段为空,所以输入看起来像这样:<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>';
?>
'$( 'plannerlist输入')'返回一个列表,你不能只是'.VAL()'名单。您必须获取列表中的所有项目。 –
@VitaliiStrimbanu嗯,这是真的...... –
您的尝试解决方案的实际目的是什么?我觉得有一个更好的方式来处理这个问题,而不是使用javascript去除输入。由于您的解决方案似乎是空字段的某种解决方法,请阅读http://xyproblem.info/,然后思考您的问题。 – dognose