JS Practical Tips Summary of Shielding Errors div Scrollbar Settings Background Picture Location etc.

  • 2021-06-28 10:54:44
  • OfStack

This article provides an example of JS's practical skills.Share it for your reference, as follows:

js Shielding Error

Place the following code in the JS script


<script type="text/javascript">
window.onerror = function(){
   alert(" A script error occurred ");
   return true;
}
alert(b);
</script>

Note: Defining onerror events should precede errors or script errors may occur

How can I prevent scrollbars from appearing in setting DIV?


style="overflow-x: hidden; overflow-y: auto;"

Page styles controlled by JS can also be represented as arrays


function init(){
  //document.getElementById("ac").style.display = "none"; Equivalent to 
  document.getElementById("ac").style["display"] = "none";
}
window.onload = init;

How to control the position of the background picture?

Because background attribute positioning is not affected by the patch factor of the object (padding), it can be positioned numerically

The default value for the background-position property is 0% 0%, from the upper left corner of the specified area


#wrapper{
  position:relative;
  background:url(../res/main_bg.png) no-repeat;
  background-position: 0% 5%;
  _background-image:none;
  display:none;
}

More readers interested in JavaScript-related content can view this site's topics: Summary of JavaScript Switching Effects and Techniques, Summary of JavaScript Finding Algorithmic Techniques, Summary of JavaScript Animation Effects and Techniques, Summary of JavaScript Errors and Debugging Techniques, Summary of JavaScript Data Structure and Algorithmic Techniques.Summary of JavaScript Traversal Algorithms and Techniques and Summary of JavaScript Mathematical Operation Usage

I hope that the description in this paper will be helpful to everyone's JavaScript program design.


Related articles: