开发者

Add video URL, with live preview option

开发者 https://www.devze.com 2023-01-25 16:16 出处:网络
I am creating a form which allows people to enter a video url. Standard input form, to accept a URL like:

I am creating a form which allows people to enter a video url. Standard input form, to accept a URL like:

http://video.google.com/videoplay?docid=1299927595688205543

I would like to add a button (within the form, which says something like [preview video]). Basically that button/link appends the link they entered into the input field, to this code:

<a href="http://video.google.com/video开发者_如何学Pythonplay?docid=1299927595688205543&lightbox[width]=610&lightbox[height]=360" class="lightbox">google video</a >

This is to be available prior to form submission.


<form id="video_upload_form" action="">
    <label for="video_input_box">Video URL</label>
    <input type="text" id="video_input_box" value="" />

    <input type="submit" value="Add Video" />
</form>

<p><a href="#" id="video_preview" class="lightbox">Preview Video</a></p>

<script type="text/javascript">
$().ready(function(){
    $('#video_upload_form').submit(function(){
        var video_url_params = '&lightbox[width]=610&lightbox[height]=360';
        var video_url = $('#video_input_box').val() + video_url_params;
        $('#video_preview').attr('href', video_url);
        return false;
    });
});
</script>

Also here it is as a JSFiddle: http://jsfiddle.net/Treffynnon/CEMpT/

You will need to do some validation on the URL supplied by the user before putting it into the preview link, but I will leave that part up to you as you have not asked for help with it in your question.

0

精彩评论

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