2014-03-03 1 views
0

2 개의 이미지와 4 개의 버튼이 있습니다. 단추를 클릭하면 단추의 색상과 배경의 배경색을 변경하고 싶습니다.어떻게하면 자바 스크립트에서 OK 버튼을 만들 수 있습니까?

function button_fn(Obj) 
{ 
    document.getElementById("div_field").style = "background-color:" + Obj.name; 
    document.getElementById("img_id").style = "border-color:" + Obj.name; 
} 

</script> 
<body> 
<fieldset> 
<legend > background color change:</legend> 
<div id="div_field"> 
<img src="home.png" name="img_png" width="200" /> 
</div> 
<form > 
<input type="button" name="red" value="Red" id="but1_id" onclick= "button_fn(this)"/> 
<input type="button" name="green" value="Green" id="but2_id" onclick="button_fn(this)"/> 
<input type="button" name="blue" value="Blue" id="but3_id" onclick="button_fn(this)"/> 
<input type="button" name="confirm" value="OK" id="confirm_id" onclick="button_fn(this)"/> 
</form> 
</fieldset> 
<div id="div_image" > 
<img src="service2.jpg" id="img_id" name="imag" width="200"border="40" /> 

</div> 

답변

0

모든 당신이 필요로하는 I S aconfirm 버튼

var r=confirm("Press a button to choose"); 
if (r==true){ 
    x = "You pressed OK!"; 
} 
else{ 
    x ="You pressed Cancel!"; 
} 
0

function button_fn(Obj) 
{ 
    Obj.style = "background-color:"+Obj.name; 
    Obj.style = "border-color:"+Obj.name; 
} 

대체 방법은 다음 스크립트입니다 :

function button_fn(Obj) 
{ 
    objId = Obj.id; 
    document.getElementById(objId).style = "background-color:"+Obj.name; 
    document.getElementById(objId).style = "border-color:"+Obj.name; 
} 
관련 문제