私はこれについて簡単な何かを見逃しているに違いないと確信しています。
showHome、showRecords、showFinanceという名前の3つのボタンがあるページがあります。また、divHome、divRecords、divFinanceという名前の3つのdivがあり、これらの各div内にiframeHome、iframeRecords、iframeFinanceという名前の3つのiframeがあります。
ここでの目標は、ページがレンダリングされた後に最初のiframeを読み込むことです。次に、ユーザーが次のボタンをクリックすると、次のiframeのソースが動的に設定され、ユーザーが外部コンテンツを表示できるようにdivが表示されます。私のドメインですが、どこか別の場所です。もちろん、3番目のボタンクリックでも同じです。iframeにロードするURLが渡され、divが表示されます。これで、ユーザーが他のボタンの1つをクリックすると、divが表示または非表示になり、コンテンツをリロードする理由がなくなります。
したがって、どのボタンがクリックされたかを追跡する必要があります。これにより、ボタンが1の場合は、divが表示または非表示になります。それ以外の場合は、iframeを設定する必要があります。私はこれのバージョンをあまりエレガントではなく機能させたので、より少ないコードでこれを書き込もうとしています。これが機能していないものです。理由はわかりますが、修正方法がわかりません。
私の現在のスクリプトは次のようになります
var showHome_clicked = '1';
var showDataMart_clicked = '0';
var showFinance_clicked = '0';
var showCost_clicked = '0';
var showSchedule_clicked = '0';
var showPerformance_clicked = '0';
var showWinsight_clicked = '0';
var pageToLoad = "http://sp2010/dashboard/0045/default.aspx";
function showRequestedContent(){
var displayedDiv = $('div.contentDiv').filter(function(){
if($(this).css('display') != 'none'){
alert(buttonClicked);
$('.contentDiv:visible').fadeOut("fast");
$("#div" + ($(this).index()+1)).show().fadeIn("slow");
}
});
}
$("input").click(function(e)
{
var buttonClicked = (e.target.id + '_clicked');
var targetIframe = (e.target.id).replace("show", "iframe");
/* Here I need to check the variable that i created, but it contains the name of my manipulated value not the 1 or 0 I need to check for, not sure how to do this? */
if(buttonClicked == '0'){
$(targetIframe).attr('src', pageToLoad + '?isdlg=1');
buttonClicked = '1';
alert("zero");
showRequestedContent;
}
else if(buttonClicked == '1'){
showRequestedContent;
alert("one");
}
});
-------------更新これは現在機能しています---------------
var buttonClicked = 'showHome';
var currentDiv = 'divHome';
$('.switchIframe').click(function(e){
e.preventDefault();
if (e.target.id != buttonClicked){
targetDiv = (e.target.id).replace("show", "div");
var $targetIframe = $($(this).data('target')),
src = $(this).data('src');
if($targetIframe.attr('src') != src){
$targetIframe.attr('src', src);
}
showDiv(targetDiv);
hideDiv(currentDiv);
currentDiv = targetDiv;
buttonClicked = e.target.id;
}
});
function showDiv(id) {
var $sDiv = $('#' + id);
$sDiv.show(500);
}
function hideDiv(id) {
var $hDiv = $('#' + id);
$hDiv.hide(200);
}
$(document).ready(function(){
$('#divHome').show();
});