admin管理员组

文章数量:1416083

Is there anyway I can change the options for the JavaScript confirm(); function? I want the options to be red and green so I can do this.

var color = confirm("Do you like red or green better");
if(color == true) {
  document.body.style.background = red;
} else {
  document.body.style.background = green;
}

Is there anyway I can change the options for the JavaScript confirm(); function? I want the options to be red and green so I can do this.

var color = confirm("Do you like red or green better");
if(color == true) {
  document.body.style.background = red;
} else {
  document.body.style.background = green;
}

Share Improve this question asked Jan 20, 2016 at 1:02 Adam OatesAdam Oates 1151 gold badge2 silver badges7 bronze badges 1
  • 1 Possible duplicate of: stackoverflow./questions/22885897/… – Halfpint Commented Jan 20, 2016 at 1:06
Add a ment  | 

2 Answers 2

Reset to default 2

No, you can't.

That happens for security reasons, styling the Confirm and Cancel buttons would open doors for attackers to abuse this feature in sort of obvious ways (Making the Cancel button hard to see, changing Confirm to Cancel, etc)

You can create a customised modal pop-up, though. Many CSS frameworks and Javascript plugins provide a basic and easy to use template for that, like Bootstrap, Foundation, and assorted jQuery and vanilla Javascript plugins

You can't customize confirm function.

If you really need to dialog customization, I remend this. jQuery UI - Modal confirmation

本文标签: htmlCan I change options in confirm() in JavaScriptStack Overflow