jQuery:如何在.html内分配变量 [英] jQuery: How to assign a variable inside of .html

查看:100
本文介绍了jQuery:如何在.html内分配变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一些jQuery来获取值,然后将其存储在变量中没问题:

I have written some jQuery to get a value and then store it in a variable no problem:

$(document).ready(function(){
    $('a.news_video_player_list').click(function () { 
    var youtube = $(this).attr('id');
      $('.news_vid_playerL').html('youtube'); 
    });
});

现在我有了变量"youtube",我想将一些HTML放入带有变量值的名为".news_vid_playerL"的div中.我的目标是这样做:

Now that I have the variable "youtube", I'd like to put some HTML inside a div named ".news_vid_playerL" with the variable value. My goal was to do this:

$('a.news_video_player_list').click(function () { 
var youtube = $(this).attr('id');
  $('.news_vid_playerL').html('<iframe title="YouTube video player" width="610" height="420" src="http://www.youtube.com/embed/+youtube+?&rel=0" frameborder="0" allowfullscreen></iframe>'); 
});

如果您在src路径中查找,您会看到我放置了一个占位符+ youtube +,我想用变量值填充该占位符.不确定如何实现.

If you look in the src path, you'll see I put a placeholder +youtube+ which I'd like to populate with the variable value. Not sure how to pull that off.

谢谢!

推荐答案

字符串串联:

$(document).ready(function(){
    $('a.news_video_player_list').click(function () {
      $('.news_vid_playerL').html('<iframe title="YouTube video player" width="610" height="420" src="http://www.youtube.com/embed/'+$(this).attr('id')+'?&rel=0" frameborder="0" allowfullscreen></iframe>'); 
    });
});

这篇关于jQuery:如何在.html内分配变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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