First get the img object by binding the id
and then add the click event
$("#img_check").click(function () {
this.src="${basePath}kaptcha.jpg"
})
This here refers to the current object. It
should be noted that src is readable, writable and can be read. The value of src can also be assigned to the URL address
Need to be replaced with your own verification code address
Will not configure the verification code?
Portal: Configure verification code
This seems to be no problem.
When you change the browser, you may find that you can only change the picture once and then click on the picture.
The reason is: Because some browsers have a cache to improve the access speed. When the image address is generated for the first visit, the image browser is saved to the local. When the second visit to this address, the browser finds that the address has been visited before and directly takes out the local picture. The reason why the picture is not refreshed
How to solve it?
It’s very simple, just make sure that the address is different each time.
plan 1:
Add a random number parameter at the end but this may still result in the same network address
Scenario 2:
Add a time parameter new date() at the back, the time will never be the same, right?
Attach the ultimate code:
$("#img_check").click(function () {
this.src="${basePath}kaptcha.jpg?"+"d="+new Date())
})
``
Every time the address is different, the natural picture is definitely different