Did not notice before, believe in jquery $ ( "#") and document.getElementById ( "") is one thing, referring to the same thing.
The project development in the use of code generation, both found different, you need to pay attention when using!
By the following tests:
JS code
function reloadValidCode(o) {
alert (o);
o.src = "${pageContext.request.contextPath }/validCodeServlet?timed=" + new Date().getMilliseconds();
}
function refresh() {
alert($("#imageYZ"));
document.getElementById("imageYZ").src = "${pageContext.request.contextPath }/validCodeServlet?timed=" + new Date().getMilliseconds();
}jsp code
<img src="${pageContext.request.contextPath }/validCodeServlet" id="imageYZ" alt="换一张" onclick="reloadValidCode(this)"/>
See? <a href="#this" onclick="refresh();"> change a </a>
I'm going to use the refresh () function
The alert ($ ( "# imageYZ")) The result is:
here it is easy to see two really different;
$ ( "# imageYZ") and document.getElementById ( "imageYZ") what the hell is. Debugging results are as follows:
$ ( "# imageYZ") [img # imageYZ]
document.getElementById ( "imageYZ") img # imageYZ
presumably, see here, I do not say, we will think of the results.
Indeed, $ ( "# imageYZ") [0] is equivalent to document.getElementById ( "imageYZ")
document.getElementById ( "errorPsd") is the dom object can be seen as javascript own object.
$ ( "# errorPsd") htm ();. is equivalent to document.getElementById ( "errorPsd") the innerHTML.
$ ( "# errorPsd") HTML ( "Change the span content");. is equivalent to document.getElementById ( " errorPsd ".) innerHTML =" change the span content ";
more content you can refer to the help documentation jquery