Javascript 选择默认类作为';主动';打开iframe
我有一段代码,每次用户单击按钮时都会打开一个不同的iframe。但是我注意到,当有人加载页面时,没有任何“默认”iframe可打开,因此iframe看起来是黑色和空的。有没有办法编辑代码,让一个类在默认情况下处于活动状态Javascript 选择默认类作为';主动';打开iframe,javascript,css,iframe,Javascript,Css,Iframe,我有一段代码,每次用户单击按钮时都会打开一个不同的iframe。但是我注意到,当有人加载页面时,没有任何“默认”iframe可打开,因此iframe看起来是黑色和空的。有没有办法编辑代码,让一个类在默认情况下处于活动状态 $(document).ready(function() { // Catch all clicks on a link with the class 'link' $('.link').click(function(e) { // Stop the link b
$(document).ready(function() {
// Catch all clicks on a link with the class 'link'
$('.link').click(function(e) {
// Stop the link being followed:
e.preventDefault();
// Get the div to be shown:
var content = $(this).attr('rel');
// Remove any active classes:
$('.active').removeClass('active');
// Add the 'active' class to this link:
$(this).addClass('active');
// Hide all the content:
$('.content').hide();
// Show the requested content:
$('#' + content).show();
});
您可以尝试这样的方法,它会尝试在页面加载时显示您的第一个链接。我不能测试,因为我没有你所有的代码,但希望这是接近你所寻找的
$(document).ready(function() {
showLink($('.link').first());
// Catch all clicks on a link with the class 'link'
$('.link').click(function(e) {
e.preventDefault();
showLink($(this));
});
function showLink(ele){
// Get the div to be shown:
var content = ele.attr('rel');
// Remove any active classes:
$('.active').removeClass('active');
// Add the 'active' class to this link:
ele.addClass('active');
// Hide all the content:
$('.content').hide();
// Show the requested content:
$('#' + content).show();
}
});
需要HTML和CSS在注释或代码段中(使用注释工具栏上的第7个图标)