使用来自 mysql 的数据清除 html 个文本文件

clearing html text files with data from mysql

我有以下表格,它从 mysql 服务器获取数据并进行计算,但是当使用重置按钮时,我无法清除包含我的 sql 数据的文本字段 下面是代码的简短部分,我可能已经扣除了一些必要的部分,但是代码可以正常工作,只是重置按钮除外。 你能帮我一下吗?

<html>
<head>

<script type="text/javascript">
$(document).ready(function() {
    $("#reset").click(function(){
       $("#find").val("");
       $("#Editbox13").val("");
       $("#Editbox14").val("");
       $("#Editbox17").val("");
    }); 
});

</script>

<?php

$find=$_POST["find"];
$find = preg_replace('/ı/', 'i', $find);  
$find = strtoupper($find);

mysql_connect("*****", "*****", "****") or die(mysql_error());
mysql_select_db("kaliteler") or die(mysql_error());

$data = mysql_query("SELECT * FROM egearge3 WHERE BASECODE LIKE '%$find%' ");

$result = mysql_fetch_array( $data );


?>

</head>
<body>
<div id="wb_Form1" style="position:absolute;left:5px;top:4px;width:1346px;height:798px;z-index:69;maxwidth:device-width;">


<form name="PRICE_CALCULATION" method="post" action="" enctype="multipart/form-data" target="_parent" id="Form1" onsubmit="return ValidatePRICE_CALCULATION()">

<input type="text" id="Editbox13" style="position:absolute;left:123px;top:406px;width:90px;height:30px;line-height:30px;z-index:17;" name="Editbox13" value="<?php if(isset($_POST['Button2'])&&$find!="") {echo $result['REALWIDTH'] ;} ?>" tabindex="12" spellcheck="false" placeholder="000">

<input type="text" id="Editbox14" style="position:absolute;left:344px;top:408px;width:90px;height:30px;line-height:30px;z-index:28;" name="Editbox14" value="<?php if(isset($_POST['Button2'])&&$find!="") {echo $result['REALWEIGHT'] ;} ?>" tabindex="13" spellcheck="false" placeholder="000">

<input type="text" id="Editbox17" style="position:absolute;left:2px;top:663px;width:1314px;height:63px;line-height:63px;z-index:41;" name="Editbox17" value="<?php if(isset($_POST['Button2'])&&$find!="") {echo $result['TYPE']."-".$result['COMPOSITION']."-".$result['PROCESS'] ;}else{echo "";}?>" spellcheck="false" placeholder="product details" rows="2" >

<input type="submit" id="Button1" name="submit[]" value="giveprice" style="position:absolute;left:516px;top:608px;width:222px;height:44px;z-index:42;" formaction="insert2.php" >

<input type="text" id="find" style="position:absolute;left:556px;top:222px;width:132px;height:36px;line-height:36px;z-index:64;" name="find" value="<?php echo $find ; ?>" spellcheck="false">

<button type="submit" id="Button2" onclick="window.reload(true);return false;" name="Button2" value="getir" style="position:absolute;left:562px;top:282px;width:71px;height:46px;z-index:65;" formaction="page8.php" >getir</button>

<input type="reset" id="btnReset" name="reset" value="Reset" style="position:absolute;left:642px;top:282px;width:56px;height:44px;z-index:68;" onclick="reset()">
</form>

</div>
</body>
</html>

reset 按钮可将表单重置为初始状态,这意味着:加载时的状态。如果您在服务器上呈现内容,reset 按钮会将表单恢复到该状态。

如果您想使用给定的 Javascript 代码清除它,您应该查看正确的选择器:您引用 ID 为 reset 的 non-existing 元素,而重置按钮的 ID 为 btnReset - 它使用 JS 处理程序调用方法 reset(),您的示例代码中未给出该方法。

所以,毕竟:您的代码存在多个问题。这些是否对您有所帮助?

您有 3 个错误:

  • 首先,您将 btnReset 中的 onclick 事件归因于一个不存在的函数 (reset())
  • 在 $(document).ready 中,您正在设置一个不存在的对象 (#reset)。应该是#btnReset
  • 即使您在 $(document).ready 中获得了正确的名称,它也不会起作用,因为重置按钮是重置类型,它只是将初始值放在字段中并且不允许 onclick 事件已设置。

因此更正:删除 onclick="reset, change $("#reset").click 到 $("#btnReset").click 并将 type="reset" 更改为 type="button" .

编辑

我想当然地认为您包含了加载 jQuery 的脚本行。如果你没有这样做,你还必须包括

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script> 标记之前或 $ 命令将不起作用。请注意,这是包含 jQuery 的众多方法之一。使用任何你想要的,但不要忘记它必须在 <script> 标签中的代码运行之前加载

像这样:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $("#btnReset").click(function(){
            $("#find").val("");
            $("#Editbox13").val("");
            $("#Editbox14").val("");
            $("#Editbox17").val("");
        }); 
    });
</script>
</head>
<body>
    <div id="wb_Form1" >
        <form name="PRICE_CALCULATION" method="post" action="" enctype="multipart/form-data" target="_parent" id="Form1" onsubmit="return ValidatePRICE_CALCULATION()">
            <input type="text" id="Editbox13" value="whatever">
            <input type="text" id="Editbox14" value="whatever">
            <input type="text" id="Editbox17" value="whatever">
            <input type="submit" id="Button1" name="submit[]" value="giveprice" formaction="insert2.php" >
            <input type="text" id="find" value="whatever">
            <button type="submit" id="Button2" onclick="window.reload(true);return false;" formaction="page8.php" >getir</button>
            <input type="button" id="btnReset" name="reset" value="Reset" >
        </form>
        </div>
</body>
</html>