我想通過組合兩個變量,一起使原始變量的名稱設置一個新的變量與已經聲明的變量相同的值。這可能聽起來令人困惑,所以這裏有一個例子:結合兩個變量設置一個新變量使用javascript設置一個已經聲明的變量
// JavaScript Document
document.write (finalVar);
$(document).ready(function()
{
var position_1 = $("#box_1").position();
var left_1 = position_1.left;
var top_1 = position_1.top;
var position_2 = $("#box_2").position();
var left_2 = position_2.left;
var top_2 = position_2.top;
var box;
var boxLength;
var boxNumber;
var selected = 0;
$("#box_1").click
(function()
{
if (selected == 1) // if a box is selected run the following
{
box = $(".selected").attr("id");
boxLength = box.length;
boxNumber = box.charAt(boxLength-1); // finds the number of the box
alert(+boxNumber);
if (box == "box_1") // if the selected box is itself then mimimise the box, remove the selected class from it and set selected to zero
{
$("#box_1").animate({height:50,opacity:0.8,left:left_1,top:top_1,borderRadius:4,MozborderRadiu s:4},(60),"swing").animate({width:50},(60),"swing").animate({opacity:0.6},(150), function()
{
$(this).removeClass("selected");
});
selected = 0;
}
else
{
$(".selected").animate({height:50,opacity:0.8,left:left_+boxNumber,top:top_+boxNumber,borderRadius:4,MozborderRadius:4},(60),"swing").animate({width:50},(60),"swing").animate({opacity:0.6},(150), function()
{
$(".selected").removeClass("selected");
$("#box_1").animate({width:900,left:60,top:0,borderRadius:10,MozborderRadius:10},(60),"swing").animate({height:500},(60),"swing").animate({opacity:1},(150), function()
{
$("#box_1").addClass("selected");
});
}
);} } // end of function for if a box is selected
else // if no box is selected run the following
{
$("#box_1").animate({width:900,left:60,top:0,borderRadius:10,MozborderRadius:10},(60),"swing").animate({height:500},(60),"swing").animate({opacity:1},(150), function()
{
$("#box_1").addClass("selected");
});
selected = 1;
}
});
$("#box_2").click
(function()
{
if (selected == 1) // if a box is selected run the following
{
box = $(".selected").attr("id");
boxLength = box.length;
boxNumber = box.charAt(boxLength-1); // finds the number of the box
alert(+boxNumber);
if (box == "box_2") // if the selected box is itself then mimimise the box, remove the selected class from it and set selected to zero
{
$("#box_2").animate({height:50,opacity:0.8,left:left_2,top:top_2,borderRadius:4,MozborderRadius:4},(60),"swing").animate({width:50},(60),"swing").animate({opacity:0.6},(150), function()
{
$(this).removeClass("selected");
selected = 0;
});
}
else
{
$(".selected").animate({height:50,opacity:0.8,left:left_+boxNumber,top:top_+boxNumber,borderRadius:4,MozborderRadius:4},(60),"swing").animate({width:50},(60),"swing").animate({opacity:0.6},(150), function()
{
$(".selected").removeClass("selected");
$("#box_2").animate({width:900,left:60,top:0,borderRadius:10,MozborderRadius:10},(60),"swing").animate({height:500},(60),"swing").animate({opacity:1},(150), function()
{
$("#box_2").addClass("selected");
});
}
);} } // end of function for if a box is selected
else // if no box is selected run the following
{
$("#box_2").animate({width:900,left:60,top:0,borderRadius:10,MozborderRadius:10},(60),"swing").animate({height:500},(60),"swing").animate({opacity:1},(150), function()
{
$("#box_2").addClass("selected");
selected = 1;
});
}
});
});
話,我想5到寫入文件......有沒有這樣做的方法嗎?我知道這可能不是正確的方式,甚至開始考慮這樣做,我只是用它作爲我正在嘗試做的同義詞。
感謝您的幫助。
爲什麼你會想要這樣做? – mrtsherman
告訴我們您真正想要解決的問題,我們可以提供比您要求的更好的解決方案。 – jfriend00
這是錯誤的 - 你能告訴我們你正在做什麼,我們可以告訴你正確的方法嗎? – Archer