开发者

Create 'dynamic' images using JS

I've a form with 2 fields. How to create a new image with the values from these 2 fie开发者_JS百科lds in the query part of the "src" URL upon form submission?


See this example (using jQuery):

    <form id="myform">
        <input type="text" value="" id="input1">
        <input type="text" value="" id="input2">
        <input type="submit" value="submit">
    </form>
    <img id="image" src="http://mydomain.com/empty.gif" />
    <script>
    $(document).ready(function () {
        $("#myform").submit(function (ev) {
            ev.preventDefault();
            var val1 = $("#input1").val();
            var val1 = $("#input2").val();
            $("#image").attr("src", "http://mydomain.com/image?val1="+val1+"&val2="+val2);
        });
    });
    </script>

change mydomain.com to you host or relative path.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜