将HTML的值传递给jQuery文件 [英] Passing value of HTML to jQuery file

查看:105
本文介绍了将HTML的值传递给jQuery文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的脚本,它运行良好!

I have a script like this, and it runs well!

<div id="player"></div>

jQuery文件:

$(document).ready(function(){
    //You can alternatively pass an object:

    $('#player').youTubeEmbed({
        video       : 'http://www.youtube.com/watch?v=uyeJXKfAcpc',
        width       : 640,      // Height is calculated automatically
        progressBar : true      // Hide the progress bar
    });
});

但是现在我想将youtube id设置为这样的输入值:

but now I want to make the youtube id in an input value like this:

<div id="player">
    <input type="hidden" name="youtube-id" value="uyeJXKfAcpc" />
</div>

并将其传递给jquery,如下所示:

and pass it to the jquery to be something like this:

$(document).ready(function(){
    //You can alternatively pass an object:
    $('#player').youTubeEmbed({
        var yid = $(this).children("input[name='youtube-id']"),
        video       : 'http://www.youtube.com/watch?v=' . yid,
        width       : 640,      // Height is calculated automatically
        progressBar : true      // Hide the progress bar
    });
});

推荐答案

您要在对象内声明一个变量,将其移至youTubeEmbed插件上方,也请使用

You are declaring a variable inside an object, move it to above the youTubeEmbed plugin, also use the .val() method to access the input's value.

var yid = $("input[name='youtube-id']").val();
$('#player').youTubeEmbed({
    video           : 'http://www.youtube.com/watch?v=' + yid,
    width           : 640,      // Height is calculated automatically
    progressBar : true      // Hide the progress bar
});

这篇关于将HTML的值传递给jQuery文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆