faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 28 people (75%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How easily swap backcolor and text color(IE5)
How to change button value easily(IE5)
How apply the runtimeStyle to swap backcolor and text color(IE5)

May 17th, 2000 06:18
Hiroto Sekine, Martin Honnen, http://www.all.co.nz/support/jpspell.htm


With IE5: Try below code.
<style>
body {
   background: "green";
   color: "gold";
}
</style>
var saveFgColor;
var saveBgColor;
function initStatus(){
	with(oBody.currentStyle){
		saveBgColor = backgroundColor;
		saveFgColor = color;
	}
}
function swap(){
	with(oBody.currentStyle){
		var temp1 = backgroundColor;
		var temp2 = color;
	}
	with(oBody.runtimeStyle){
		backgroundColor = temp2;
		color = temp1;
	}
}
function reset(){
	var e = event.srcElement;
	if (e.value == 'W/B'){
		var fgColor = 'black';
		var bgColor = 'white';
		e.value = 'Resume';
		e.title = 'Resume orginal color';
	} else {
		var fgColor = saveFgColor;
		var bgColor = saveBgColor;
		e.value = 'W/B';
		e.title = 'Reset screen color';
	}
	with(oBody.runtimeStyle){
		backgroundColor = bgColor;
		color = fgColor;
	}
}
<body OnLoad="initStatus();" id="oBody">
<p>This is sample text.</p>
<p align="center" id="BTN">
<input type="button" title="Swap Text & Background color" 
value="T<-->B" name="swap" id="SWAP" OnClick="swap();" /><input 
type="button" title="Reset screen color" value="W/B" name="wb" 
id="RESET" OnClick="reset();" />
</p>