JavaEE ------ Add a function written by yourself in JavaScript
In js writing, we have encountered such a problem. We need to trim the obtained String. For example, if we want to remove the space of the String, we want to call trim, but it does not exist. So I need to add such a function
Simple use of trim.
We can write in js like this: use the regular expression method.
String. prototype. trim = function () {var p =/^ \ s */; var str = this. replace (p, ""); p =/\ s * $/; str = str. replace (p, ""); return str ;};
Then we can implement it in js.
Function query () {// note that there are multiple identical "studId, studName, deptId" elements on the page. It is best to use the id to obtain var studId = document. getElementsByName ("studId") [1]. value; studId = studId. trim (); var name = document. getElementsByName ("studName") [1]. value; name = name. trim ();}