相关疑难解决方法(0)

使用jQuery重置多阶段表单

我有一个带有标准复位按钮的表格,因此编码:

<input type="reset" class="button standard" value="Clear" />
Run Code Online (Sandbox Code Playgroud)

麻烦的是,表示表单属于多阶段排序,因此如果用户填写一个阶段然后稍后返回,则单击"清除"按钮时,不会重置各个字段的"记住"值.

我认为附加一个jQuery函数来遍历所有字段并"手动"清除它们就可以了.我已经在表单中使用了jQuery,但我只是起步速度,所以我不知道如何解决这个问题,除了通过ID单独引用每个字段,这看起来效率不高.

TIA提供任何帮助.

forms jquery reset

348
推荐指数
9
解决办法
27万
查看次数

如何重置输入字段?jQuery的

我已经阅读了几个帖子,包括这个,这个,但我似乎无法在提交后清除输入字段.最基本/最基本的方法是什么?

目前我有这个:

$(document).ready(function(){
    $('form[name=checkListForm]').on('submit', function() {
          // prevent the form from submitting
          event.preventDefault();
          var toAdd = $(this).find('input[name=checkListItem]').val();
          $('.list').append("<div class='item'>" + toAdd + "</div>")
          $('input[name=checkListItem').reset();
        });
});
Run Code Online (Sandbox Code Playgroud)

我的HTML是:

<!DOCTYPE html>
<html >
  <head>
    <meta charset="UTF-8">  
    <link rel="stylesheet" href="stylesheet.css">     
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    <script type="text/javascript" src="script.js"></script>
  </head>
  <body>
    <h2>To Do</h2>
    <form name="checkListForm">
      <input type="text" name="checkListItem" />
      <button type="submit" id="button">Add!</button>
    </form>
    <br/>
    <div class="list"></div>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

9
推荐指数
1
解决办法
4万
查看次数

重置按钮无法在html(php)中工作

我已将输入类型重置按钮放在窗体内,但仍然无法正常工作.

<form method='post' action='process/update_news_action.php' >
<tr>
   <td colspan='2' class="col-md-4">Update News Content</td>
</tr>
<tr >
   <td colspan='2' class="col-md-8"><textarea name="news" id="text"><?php echo  $rows["news"] ;  ?></textarea></td>
</tr>
<tr>
   <td class="col-md-4"><input name='submit' type="submit" value='Publish' class="btn btn-success" /></td>
   <td class="col-md-4"><input name='reset' type="reset" value='Reset' class="btn btn-primary" /></td>
</tr>
</form>
Run Code Online (Sandbox Code Playgroud)

我也试过了 <button type="reset" value="Reset">Reset</button>

html php

3
推荐指数
2
解决办法
1万
查看次数

如何在ajax提交后清除表单?

我有一个小联系表格.发送邮件正在运行,但表单在提交后仍保留文本.我搜索并尝试了一些代码来清除它但没有成功.

// JavaScript Document
$('#contact-form').submit(function (e) {
"use strict";
e.preventDefault();
$.ajax({
    type: "POST",
    url: "contactform.php",
    data: $(this).serialize(), //get form values
    sucess: function (data) {
        document.getElementById("contact-form").reset();
    }

}).done(function (data) {
    console.log(data); // will contain success or invalid 
});
});
Run Code Online (Sandbox Code Playgroud)

还有一些php

<?php
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$message = $_POST["message"];

$EmailTo = "marcin@rmonline.com";
$Subject = "New Message Received";

// prepare email body text
$email_content .= "Firstname: $firstname\n";
$email_content .= "Lastname: $lastname\n";
$email_content .= "Email: $email\n"; …
Run Code Online (Sandbox Code Playgroud)

html php forms ajax

1
推荐指数
1
解决办法
5613
查看次数

提交后重置HTML表单

const scriptURL = 'URL'
const form = document.forms['myform']

form.addEventListener('submit', e => {
  e.preventDefault()
  fetch(scriptURL, {
      method: 'POST',
      body: new FormData(form)
    })
    .then(response => console.log('Success!', response))
    .catch(error => console.error('Error!', error.message))
});
Run Code Online (Sandbox Code Playgroud)
<form name="myform">
  <div class="col-md-6 col-sm-6">
    <div class="form-group">
      <label for="email" class="sr-only">Email</label>
      <input name="email" class="form-control" type="email" placeholder="Email" required>
    </div>
  </div>
  <div class="col-md-6 col-sm-6">
    <button type="submit" class="btn btn-default btn-block">Subscribe</button>
  </div>
</form>
Run Code Online (Sandbox Code Playgroud)

处理表单提交后如何重设表单?

这是我目前正在做的事情:

 form.addEventListener('submit', e => {
                          e.preventDefault()
                          fetch(scriptURL, { method: 'POST', body: new FormData(form)})
                          .then(response => console.log('Success!', response))
                          .catch(error => console.error('Error!', error.message)) …
Run Code Online (Sandbox Code Playgroud)

html javascript

1
推荐指数
1
解决办法
6197
查看次数

将表单的所有输入重置为默认值而不重新加载

我想重置我在表单(文本框,选择,复选框,单选按钮,......)中输入的所有值,就像我重新加载网页,但是当我触摸按钮时.

$("#button").click(function () {
     //Here the code that I need   
});
Run Code Online (Sandbox Code Playgroud)

html javascript forms jquery default-value

0
推荐指数
1
解决办法
8971
查看次数

标签 统计

html ×5

forms ×3

javascript ×3

jquery ×3

php ×2

ajax ×1

default-value ×1

reset ×1