【问题标题】:clearing html text files with data from mysql使用 mysql 中的数据清除 html 文本文件
【发布时间】:2018-03-23 21:22:47
【问题描述】:

我有下面的表格,它从 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>

【问题讨论】:

  • 尝试使用 .on 代替直接 .click .
  • 请停止使用 mysql_* 函数...它们很旧,不安全且损坏,在 PHP 5.5 中已被弃用,并在 PHP 7.0 中完全删除

标签: javascript php reset


【解决方案1】:

你有 3 个错误:

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

所以要更正:删除 onclick="reset,将 $("#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>

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

像这样:

<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>

【讨论】:

  • 首先感谢您的宝贵时间。我已经尝试过了,但它仍然无法正常工作:(
  • 这三个步骤你做到了吗?删除 onclick="reset,将 $("#reset").click 更改为 $("#btnReset").click 并将 type="reset" 更改为 type="button"
  • 我认为现在进行更改是我的错。非常感谢您的所有帮助
  • 如果回答对你有用,也可以点赞,谢谢:)
【解决方案2】:

reset 按钮将表单重置为初始状态,即:加载时的状态。如果您在服务器上渲染内容,reset 按钮会将表单返回到该状态。

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

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

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多