php - 清除 PHP 回显值输入字段
问题描述
我有一个表单,它通过 php 的 echo 函数显示从表中单击的值。回显逻辑如下:
//reading input
if(isset($_POST['add'])){
$scrid=$_POST['sc'];
$desc=mysqli_real_escape_string($_POST['desc']);
$cb=mysqli_real_escape_string($_POST['created']);
$version=mysqli_real_escape_string($_POST['version']);
if($scrid !=0){
if(empty($desc)){$result="Description cannot be Empty";}
elseif(empty($cb)){$result="Created By cannot be Empty";}
elseif(empty($version)){$result="Version cannot be Empty";}
else{
echo $t."empty";
$sql="INSERT INTO testmaster(ScreenID,Description,createdBy,version) VALUES('$scrid','$desc','$cb','$version');";
if(mysqli_query($link,$sql)){
header('Location: testmaster.php');
}else{
echo "Query failed";
}
}
}
}
//passing table values,,,,, works perfectly fine...
if(mysqli_num_rows($sol)>0){
while($row=mysqli_fetch_assoc($sol)){
echo"<tr>";
echo"<td><a href=testmaster.php?testid=".$row['tid'].">".$row['Description']."</a></td>";
echo"<td>".$row['createdBy']."</td>";
echo"<td>".$row['version']."</td>";
echo "</tr>";
}
}
}
if(isset($_GET['testid'])){
$t=$_GET['testid'];
$query="SELECT * FROM testmaster WHERE tid='$t';";
if($sol=mysqli_query($link,$query)){
$modif=mysqli_fetch_assoc($sol);
$d=$modif['Description'];
$c=$modif['createdBy'];
$v=$modif['version'];
$sc=$modif['ScreenID'];
}
//These are the input fields
echo'<td><textarea name="desc" class="form-rounded" cols=50 rows=2
placeholder="Description">'.$d;
echo'</textarea></td>';
echo'<td><input type="text" name="created" class="form-control"
placeholder="Created By" value='.$c.'>';
echo'</td>';
//cancel
echo "<input type='reset' class='btn button2' name='cancel' id='cancel' value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >" ;
取消按钮和在 JQuery 中清除文本字段值中指定的 javascript 代码都不起作用。
我想这是因为我附和它。任何人都可以帮我吗?提前致谢.... :)
PS所有输入字段和取消按钮都在里面......
解决方案
如果您在代码中包含了 JQuery,那么您可以这样做:
- 将clear-onclick(或其他名称)类添加到您希望为空的所有字段
- 将onclick处理程序添加到按钮
表格代码
echo'<td><textarea name="desc" class="form-rounded clear-onclick" cols=50 rows=2
placeholder="Description">'.$d;
echo'</textarea></td>';
echo'<td><input type="text" name="created" class="form-control clear-onclick"
placeholder="Created By" value='.$c.'>';
echo'</td>';
按钮代码
<input type='reset' class='btn button2' name='cancel' id='cancel' onclick="javascript: $('.clear-onclick').val(null)" value='Cancel' style='height:12px; text-align:center; margin-left:10px;' >
您可以按如下方式包含 jQuery:
echo '<script src="https://code.jquery.com/jquery-3.3.1.js"></script>';
推荐阅读
- javascript - 悬停在ul子元素效果ul后样式
- sql - SQL将列拆分为X列然后插入到表中
- protractor - 量角器检查单选按钮
- javascript - 从另一个 JS 文件(不是游戏状态)调用函数 Phaser js
- mysql - 在mysql中建立索引的最佳方法是什么
- node.js - frontend-maven-plugin 检测到错误的架构导致错误的节点下载 url
- javascript - Javascript - 如何更新 cookie 以便拨打新号码而不是默认号码?
- jquery - 我只想在按钮单击时显示隐藏的移动格式?
- c# - 为什么我不能在 CudaFy 库的 c# 代码中设置断点?
- apache - 防止Apache2.2 web服务器中的暴力密码攻击