Home>
(function () {
window.alert=function (text) {
 text=text.tostring (). replace (/\\/g, "\\"). replace (/\ n/g, "<br />").replace(/\r/g,"< ;br />");//Parse newline characters in alert content
 var alertdiv="<div>" + text + "&br;<input type =" submit "name =" button "value =" OK "onclick =" $(this) .parent (). remove ( );"/></div>";//Custom div popup
 $(document.body) .append (alertdiv);//Load the div dynamically
 $("#alertdiv"). css ({"margin-left":$("#alertdiv"). width ()/2 * (-1) -20, "margin-top":$("#alertdiv" ) .height ()/2 * (-1) -20});//Set the offset value,Implement div centering
 $("#alertdiv"). show ();//show
};
}) ();

Note:The above code can adapt alert content length,Support line breaks,When called, it is no different from the original alert function.

The complete example code is as follows:

<script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
(function () {
window.alert=function (text) {
 text=text.tostring (). replace (/\\/g, "\\"). replace (/\ n/g, "<br />").replace(/\r/g,"< ;br />");//Parse newline characters in alert content
 var alertdiv="<div>" + text + "&br;<input type =" submit "name =" button "value =" OK "onclick =" $(this) .parent (). remove ( );"/></div>";//Custom div popup
 $(document.body) .append (alertdiv);//Load the div dynamically
 $("#alertdiv"). css ({"margin-left":$("#alertdiv"). width ()/2 * (-1) -20, "margin-top":$("#alertdiv" ) .height ()/2 * (-1) -20});//Set the offset value,Implement div centering
 $("#alertdiv"). show ();//show
};
}) ();
</script><input type="submit" name="button" value="click to pop up alert custom window" onclick="alert (" This is an alert popup \ nsupports \\ n line break ")" " />

The screenshot of the running effect is as follows:

  • Previous Lua to configure the anti-theft function of the Nginx server
  • Next Python batch production method of radar chart