Styling the "OK" Button in an Alert Box
In Javascript, the alert() function displays a modal alert box containing a message and an "OK" button. While the overall appearance of the alert box is determined by the system settings, it's not directly subject to CSS customization.
Customizing Alert Box Functionality
To modify the styling of the "OK" button, consider creating an HTML element to replicate the functionality of alert(). For example, using jQuery UI's Dialog feature offers a close approximation:
Example with jQuery UI Dialog:
<!doctype html> <html lang="en"> <head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $(function() { $("#dialog").dialog(); }); </script> </head> <body> <div>
In this example, we've created a dialog box with the title "Customized Alert." You can now use CSS to customize its appearance, including the "OK" button.
Note: The jQuery UI Dialog requires additional code to implement the functionality of alert(), such as displaying the message and closing the dialog when the button is clicked.
The above is the detailed content of How Can I Style the 'OK' Button in a Javascript Alert Box?. For more information, please follow other related articles on the PHP Chinese website!