JQ / JS在弹出窗口中无法通过ID访问DOM ID元素

时间:2018-08-21 14:20:08

标签: javascript jquery dom

我从父母那里打开了一个名为win2的新窗口。我正在尝试更改标题为ID的DIV中的文本。我可以访问视频播放器元素来播放视频,但是由于某种原因,由于我的生活,我无法弄清楚如何更改文本:

var extS = $(win2.document).contents().find('#videosource'); //works fine
var extP = $(win2.document).contents().find('#videoplayer'); //works fine
var extT = $(win2.document).contents().find('#Title'); //doesn't work


extP.get(0).pause();
extS.attr('src', PlayMe);
extP.get(0).load();
extS.get(0).play(); //this all works fine
extT.html('Now Playing'); //doesn't work

也尝试过:

 $(win1.document).getElementById('#Title').html('Now Playing'); //doesn't work

以下是子窗口中的HTML:

<html>
<head> 
<title>Video Window</title>
<link href="CSS.css" rel="stylesheet" type="text/css">
</head>

<body>
    <div id="Wrapper">

    <div class="videocontent">
    <div class="currentvideo"></div>
    <div class="VideoWindowTitle" id="Title">Video Window</div>
    <video id="videoplayer" autoplay loop poster="Blank Video.png" width="100%">
        <source id="videosource" src="" type="video/mp4">
        Your browser does not support the video tag.
    </video>
    </div>
    </div>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

我想这应该是对细节注意的警告。

以下工作有效:

var extT = $(win1.document).contents().find('#displayvideo')

exT.html(title);

问题是html视频播放器设置为自动播放,并且当我随后通过属性执行播放时会破坏脚本。当然,在那之后,我尝试运行此特定的html更改。因此,到那时为止,一切都会正常进行,而我忽略了正确地排除故障。

相关问题