Summary of Common Problems and Quick Solutions in jquery

  • 2021-06-28 11:11:56
  • OfStack

1 During the development of an open chat room, two pieces of data were inserted when the ajax submission form was used to insert the data into the database.

Solution, after the ajax function returns, return false.


$("#btn").click(function(){
$.ajax({
  do something 
});
return false;

})

2 Remove an attribute of the selected element using removeattr

3 The time-related functions in javascript are setInterval ("function", millisec ["lang"]) and setTimeout ("function", millisec)

And clearTimeout (object) Clear the set setTimeout object clearInterval (object) Clear the set setInterval object.setInterval automatically executes the function once every other time and returns an object for use with the clearInterval function to clear the settings.

Functions to get local time


function getTime(){
  var datTime = new Date();
  var sep1 = "-",sep2=":";
  
  var year = datTime.getFullYear();
  var mon = datTime.getMonth()+1;
  var day = datTime.getDate();
  var hour = datTime.getHours();
  var min = datTime.getMinutes();
  var sec = datTime.getSeconds();
  time = year + sep1 + mon + sep1 + day + " "+ hour + sep2 + min + sep2 + sec;
  $("#content1>p").text(time);
  
}

Errors are inevitable in the process of learning.If you do not understand or have questions during the reading process.Welcome to make corrections.


Related articles: