刷新页面后如何清除文本框值需要帮助?实际上我在提交表单后仍然使用搜索文本框显示文本框内的值它工作正常,但我想在刷新页面时清除值。
这是我的代码,
localStorage.yearlySearchFilter = $("#yearly_search_id").val();
$("#yearly_search_id").val(localStorage.yearlySearchFilter);
使用本地存储,
#include <iostream>
using namespace std;
int main()
{
int input;
int tmp;
int counter = 1;
int max_num=0;
int min_num;
//prompt user for integer amount
cout << "How many integers would you like to enter? " << endl;
cin >> input;
cout<< "Please enter " << input << " integers." << endl;
tmp = input;
//loop for requested amount with a test for each input
while (counter <= tmp){
cin >> input;
//if smaller than previous number it is the minimum
if (input < min_num){
min_num = input;
counter++;
}
// if larger than previous number it becomes max number
else if (input > max_num){
max_num = input;
counter++;
}
//continue loop if number isn't bigger than max or smaller than min
else {
counter++;
}
}
//display the max and min
cout << "min: "<< min_num << endl;
cout << "max: " << max_num<< endl;;
return 0;
}
答案 0 :(得分:1)
在Javascript中你可以这样做:
function init() {
document.getElementById("normal_search").value = "";
}
window.onload = init;
或者在jQuery中只需:
$(document).ready(function() {
$("#normal_search").val('');
});
答案 1 :(得分:1)
您可以这样做(清除所有表格输入字段)。
当你使用localstorage时。试试这个
$(document).ready(function() {
localStorage.clear();
//localStorage.removeItem("name of localStorage variable you want to remove");
});
答案 2 :(得分:1)
而不是这个
localStorage.yearlySearchFilter = $("#yearly_search_id").val();
$("#yearly_search_id").val(localStorage.yearlySearchFilter);
使用此:
localStorage.yearlySearchFilter = $("#yearly_search_id").val();
页面加载时,您在搜索框中找不到任何值。
答案 3 :(得分:0)
您可以使用以下代码重置表单字段:
$(document).ready(function() {
$('form').find("input[type='text'],textarea").val("");
});