我更改了以下对象ID的ID ..我试图在点击时更改视频:
<object id="aeroVideo" class="BrightcoveExperience">
<param name="bgcolor" value="#FFFFFF" />
<param name="width" value="480" />
<param name="height" value="270" />
<param name="isVid" value="true" />
<param name="isUI" value="true" />
<param name="dynamicStreaming" value="true" />
<param name="wmode" value="transparent" />
</object>
<div id="pic2">
<div id="pic2a"></div>
<div id="pic2b"></div>
</div> <!-- end of pic2 -->
<script type="text/javascript">
$( document ).ready(function() {
var aeroVideo = $("#aeroVideo");
$('#pic2a').click(function(){
console.log("inside pic2a");
if (aeroVideo.length == 0){
aeroVideo = "myExperience3427230656001";
console.log("inside pic2a without variable set");
}
else if (aeroVideo.length != 0){
aeroVideo = "myExperience3427230656001";
console.log("inside pic2a with variable set");
}
});
$('#pic2b').click(function(){
console.log("inside pic2b");
if (aeroVideo.length == 0){
aeroVideo = "myExperience3427216723001";
console.log("inside pic2b without variable set");
}
else if (aeroVideo.length != 0){
aeroVideo = "myExperience3427216723001";
console.log("inside pic2b with variable set");
}
});
});
</script>
跑步时的控制台告诉我我在pic2a或pic2b里面有变量设置(从不没有变量设置)但是它根本没有像插入视频的字符串那样改变视频名称...
答案 0 :(得分:0)
您将aeroVideo
设置为字符串值,而不是更改ID。
您想要更改此内容:aeroVideo = 'myExperience3427230656001';
对此:aeroVideo.attr('id', 'myExperience3427230656001');
。
此外,如果aeroVideo为空({jQuery没有找到它),aeroVideo.length == 0
会返回true
,所以您可能只想要aeroVideo.length
。
答案 1 :(得分:0)
即兴表达问题。看起来代码尝试将字符串设置为aeroVideo。至少它必须使用DOM对象的属性