Javascript 如何使用此代码打开div?
这个小代码打开了一个窗口,其中有图片(homer.jpg),但我想打开DIV,例如id为的DIV:#exampledivJavascript 如何使用此代码打开div?,javascript,jquery,colorbox,Javascript,Jquery,Colorbox,这个小代码打开了一个窗口,其中有图片(homer.jpg),但我想打开DIV,例如id为的DIV:#examplediv 我应该在代码中更改什么?使用此代码段添加它,尽管您必须更改一些内容: $(document).ready(function(){ setTimeout(function() { $.fn.colorbox({href:"res/homer.jpg", open:true}); }, 1500); }); 你是说像这样的事吗 对不起,你
我应该在代码中更改什么?使用此代码段添加它,尽管您必须更改一些内容:
$(document).ready(function(){
setTimeout(function() {
$.fn.colorbox({href:"res/homer.jpg", open:true});
}, 1500);
});
你是说像这样的事吗 对不起,你的问题不清楚 HTML
$('.element').attr('id', 'newID');
jQuery
#examplediv{
position: absolute;
margin: 200px;
padding: 5px;
border: 2px solid #000;
}
#examplediv > img{
width: 120px; height: 120px;
}
$(文档).ready(函数(){
$('#examplediv').html('');
});
捕获所需div的HTML,然后将其作为参数提供给colorbox调用:
$(document).ready(function(){
$('#examplediv').html('<img src="res/homer.jpg" alt="" />');
});
你的意思是“打开”是弹出的吗?请你进一步解释一下这个问题,我很难理解它。$.colorbox({html:$('examplediv').html());不清楚你在问什么:请澄清你的具体问题或添加额外的细节,以突出你所需要的。正如目前所写的,很难准确地说出你在问什么。
$(document).ready(function(){
$('#examplediv').html('<img src="res/homer.jpg" alt="" />');
});
$(document).ready(function() {
setTimeout(function() {
var myhtml = $('#examplediv').html();
$.colorbox(html: myhtml, open: true);
}, 1500);
});