如何动态检查和增加div id';什么是javascript?

如何动态检查和增加div id';什么是javascript?,javascript,jquery,html,onclick,jwplayer,Javascript,Jquery,Html,Onclick,Jwplayer,我有一个使用Longtail Video的JW播放器的视频表。单击表中的图像时,视频将以id为媒体模式的模式启动。这是我正在谈论的页面: 这是模式的Javascript: $(".mediamodal").unbind('click'); $(".mediamodal").click(function () { $('.reveal-modal-bg').unbind('click'); $('.close-reveal-modal').unbind('click');

我有一个使用Longtail Video的JW播放器的视频表。单击表中的图像时,视频将以id为
媒体模式的模式启动。这是我正在谈论的页面:

这是模式的Javascript:

$(".mediamodal").unbind('click');
$(".mediamodal").click(function () {
    $('.reveal-modal-bg').unbind('click');
    $('.close-reveal-modal').unbind('click');
    $('#mediamodal').remove();
    $('body').append('<div id="mediamodal" class="reveal-modal large" style="width:675px; margin-left:-415px;"><div id="mediaplayer"><script type="text/javascript">SetupMediaPlayer("' + $(this).attr('rel').toLowerCase() + '");</script></div><div id="livepoll_min" style="padding-top:20px;"></div><a class="close-reveal-modal">&#215;</a></div>"');
    $('#mediamodal').reveal({
        animation: 'fadeAndPop',                   //fade, fadeAndPop, none
        animationspeed: 300,                       //how fast animtions are
        closeonbackgroundclick: true,              //if you click background will modal close?
        dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
    });
    $('.reveal-modal-bg').click(function () {
        $("#mediaplayer").remove();
        socket.disconnect();
    });

    $('.close-reveal-modal').click(function () {
        $("#mediaplayer").remove();
        socket.disconnect();
    });
$(.mediamodel”).unbind('click');
$(“.mediamodel”)。单击(函数(){
$('.REVEL modal bg')。解除绑定('单击');
$('.close-reveal-modal')。解除绑定('click');
$('#mediamodel')。删除();
$('body').append('SetupMediaPlayer('+$(this).attr('rel').toLowerCase()+');&215;“);
$(“#mediamodal”)。显示({
动画:“fadeAndPop”,//fade,fadeAndPop,无
动画速度:300,//动画有多快
closeonbackgroundclick:true,//如果单击background将关闭吗?
dismissmodalclass:“close-reveal-modal”//将关闭打开模式的按钮或元素的类
});
$('.显示模式bg')。单击(函数(){
$(“#mediaplayer”).remove();
socket.disconnect();
});
$('.close-reveal-modal')。单击(函数(){
$(“#mediaplayer”).remove();
socket.disconnect();
});
这在桌面浏览器上非常有效,但在iPad上不行。我在Longtail的页面上查找了为什么失败,他们说每个浏览器都需要一个唯一的div id。我意识到这是一个问题,因为我正在生成div onclick


如何动态更改每个视频的div id?

您可以使用全局计数器:

var hiImACounter = 0;

$(".mediamodal").unbind('click');
$(".mediamodal").click(function () {
    $('.reveal-modal-bg').unbind('click');
    $('.close-reveal-modal').unbind('click');
    $('#mediamodal' + hiImACounter++).remove(); // <--- increment after the operation
    $('body').append('<div id="mediamodal'+hiImACounter+'" class="reveal-modal large" style="width:675px; margin-left:-415px;"><div id="mediaplayer'+hiImACounter+'"><script type="text/javascript">SetupMediaPlayer("' + $(this).attr('rel').toLowerCase() + '");</script></div><div id="livepoll_min" style="padding-top:20px;"></div><a class="close-reveal-modal">&#215;</a></div>"');
    $('#mediamodal'+hiImACounter).reveal({
        animation: 'fadeAndPop',                   //fade, fadeAndPop, none
        animationspeed: 300,                       //how fast animtions are
        closeonbackgroundclick: true,              //if you click background will modal close?
        dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
    });
    $('.reveal-modal-bg').click(function () {
        $("#mediaplayer"+hiImACounter).remove();
        socket.disconnect();
    });

    $('.close-reveal-modal').click(function () {
        $("#mediaplayer"+hiImACounter).remove();
        socket.disconnect();
    });
var hiImACounter=0;
$(“.mediamodel”).unbind('click');
$(“.mediamodel”)。单击(函数(){
$('.REVEL modal bg')。解除绑定('单击');
$('.close-reveal-modal')。解除绑定('click');

$('#mediamodel'+hiImACounter++)。删除();//您可以保留一个计数器,并为每次单击增加它,以确保一个唯一的div id?为什么不从dom中删除具有该id的div?这样,您只需在单击时创建一个新的div..并在关闭时删除。由于您在创建后无论如何都要绑定事件。如果达到这样的程度,您的应用程序的设计通常是这样的我主要失败了。我认为重用也是正确的答案,但OP就是这么做的。容器div和player元素每次都会被重新创建。因此,即使删除它,也不能重用相同的id。@JosephMarikle啊。。没错。。那就是wierd