开发者

Can an onsubmit event insert an image into the page before the page submits?

开发者 https://www.devze.com 2023-03-22 15:05 出处:网络
Can an onsubmit ev开发者_如何学JAVAent insert an image into the page before the page submits/transfers control to the next page?

Can an onsubmit ev开发者_如何学JAVAent insert an image into the page before the page submits/transfers control to the next page?

I am using classic asp.


Of course. The function resolves before the form is submitted.

(Although… while an img element may be inserted into the page, it might not load before the browser has gone to the next one, and even if it does, the user might not have time to see it clearly)


Yes . You can insert the HTML code (through javascript):

<img src="imgsrc">

But it takes a little time for loading the image. The form send the user to another page in new window or in the same window? Why would you want to insert an image in the current window if the page will be replaced with the new one?


Yes you can do this. It would be easier (for me to write) if you used jquery:

html:

<form id="myForm" action="">
    <input type="text" id="someId" />
    <input type="submit" id="submit" value="submit" />
</form>

and then JavaScript would be:

$(document).ready(function() {
    $("#myForm").submit(function() {
        $(this).append('<img src="someImage.jpg" alt="" />');
    });
});

http://jsfiddle.net/rYUbQ/

But like others have said it might not be loaded and displayed before the form submits so you might want to instead look in to preloading the image and then just setting it to visible before the page submits.

0

精彩评论

暂无评论...
验证码 换一张
取 消