SoFunction
Updated on 2025-03-06

Example code to implement alert using JavaScript

I won’t say much nonsense, I will just post the code to you. The specific code is as follows:

<script> 
   = alert; 
  function alert(data) { 
    var MainDiv = ("div"), 
      p = ("p"), 
      AllPage = ("div"), 
      btn = ("div"), 
      textNode = (data ? data : ""), 
      btnText = ("Sure"); 
    // Control style    css(AllPage, { 
      "position": "fixed", 
      " _position": "absolute", 
      " width": "100%", 
      "height": "100%", 
      "left": "0", 
      "top": "0", 
      "background": "rgba(0, 0, 0,0.5)", 
      "-moz-opacity": "0.5", 
      "filter": "alpha(opacity=50)", 
      "z-index": "97", 
    }); 
    css(MainDiv, { 
      "position": "fixed", 
      "left": "0", 
      "right": "0", 
      "top": "30%", 
      "width": "14rem", 
      "height": "5rem", 
      "padding-top":"0.5rem", 
      "margin": "0 auto", 
      "background-color": "white", 
      "font-size": "0.75rem", 
      "text-align": "center", 
      "position": "relative", 
      "border-radius": "5px 5px 5px 5px", 
    }); 
    css(btn, { 
      "background": "#de241b", 
      "color": "white", 
      "width": "6rem", 
      "margin-left": "4rem", 
      "margin-bottom":"0.25rem", 
      "height": "1.5rem", 
      "border-radius": "5px 5px 5px 5px", 
      "position": "absolute", 
      "padding-top":"0.5rem", 
      "bottom":"0", 
    }) 
    // Inside structure    (textNode); 
    (btnText); 
    (p); 
    (btn); 
    (MainDiv); 
    // Displayed in the page as a whole    ("body")[0].appendChild(AllPage); 
    //Scrolling is prohibited    $("body").on("touchmove", function (event) { 
      ; 
    }, false) 
    // Confirm the binding click event to delete the tag     = function () { 
      (AllPage); 
      //Enable scrolling      $("body").off("touchmove"); 
    } 
  } 
  function css(targetObj, cssObj) { 
    var str = ("style") ? ("style") : ""; 
    for (var i in cssObj) { 
      str += i + ":" + cssObj[i] + ";"; 
    } 
     = str; 
  } 

The above is the example code for using JavaScript to implement alert that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!