JavaScript object attribute inspection, addition, deletion, access operation examples_javascript skills
Check Properties var mouse = { “name”: “betta”, “age”: 3, “varieties”: “milaoshu” } mouse.hasOwnProperty(“name”); // true mouse.hasOwnProperty(“sex”); //false Add attributes Define an object dog, then assign various attributes, then assign the color attribute, and finally traverse all attributes and values var dog={ name:”Mango”, type:”King of Clubs”, eat:function(){ alert(“eat”); } } Object.prototype.color=”white”; var name; for(name in dog){ document.write(name+” “+dog[name]+””) } The effect is as follows name mango type king of meetings eat function (){ alert(“eat”); } color white Delete attributes var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } delete cat.name; cat.sex = undefined; cat.color = null; alert(“Whether the name attribute exists:” + cat.hasOwnProperty(“name”)); //false alert(“Whether the sex property exists:” + cat.hasOwnProperty(“sex”)); //true alert(“whether the color property exists:” + cat.hasOwnProperty(“color”)); //true Access properties var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } var name1 = cat.name; //Access object properties through dot operator var name2 = cat[“name”]; //Access object properties through the bracket operator There are two ways to create objects var obj = new Object(); obj.name = “MangGuo”; obj.age = 25; var obj = { name: “MangGuo”, //name is the attribute name, “MangGuo” is the value age: 25 }
JavaScript object attribute inspection, addition, deletion, access operation examples_javascript skills
Check Properties var mouse = { “name”: “betta”, “age”: 3, “varieties”: “milaoshu” } mouse.hasOwnProperty(“name”); // true mouse.hasOwnProperty(“sex”); //false Add attributes Define an object dog, then assign various attributes, then assign the color attribute, and finally traverse all attributes and values var dog={ name:”Mango”, type:”King of Clubs”, eat:function(){ alert(“eat”); } } Object.prototype.color=”white”; var name; for(name in dog){ document.write(name+” “+dog[name]+””) } The effect is as follows name mango type king of meetings eat function (){ alert(“eat”); } color white Delete attributes var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } delete cat.name; cat.sex = undefined; cat.color = null; alert(“Whether the name attribute exists:” + cat.hasOwnProperty(“name”)); //false alert(“Whether the sex property exists:” + cat.hasOwnProperty(“sex”)); //true alert(“whether the color property exists:” + cat.hasOwnProperty(“color”)); //true Access properties var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } var name1 = cat.name; //Access object properties through dot operator var name2 = cat[“name”]; //Access object properties through the bracket operator There are two ways to create objects var obj = new Object(); obj.name = “MangGuo”; obj.age = 25; var obj = { name: “MangGuo”, //name is the attribute name, “MangGuo” is the value age: 25 }
JS acquisition, addition, and deletion operations for HTML tag select_javascript skills
The code is as follows: (empty) 1 The code is as follows: //Get the html controlvar select = document.getElementsByName(“aaa”)[0]; select.selectedIndex = index; //Create a new Option objectnew Option(text,value) new option(text,value,defaultSelected,selected text: string, specifying the text attribute of the option object (that is, the text between ) value: String, specifies the value attribute of the option objectdefaultSelected: Boolean value, specifies the defaultSelected attribute of the option objectselected: Boolean value, specifies the selected attribute of the option object // Add Option to select select.add(new Option(text,value)) //Deleteselect.options.remove(index) //Delete all at onceselect.length = 0;
Java commonly used digital tools for large number multiplication, addition, and subtraction (2)
The previous article shared a small function of converting numbers into Chinese characters. Here I will share a function of multiplying, adding, and subtracting large numbers. Without going into too much detail about the rest, let me first talk about the calculation principles of each function. Ⅰ. Multiplication operation Why do I talk about multiplication first? Because I did the multiplication first. In fact, there are many ideas, but in the end I referred to a calculation scheme on the Internet and made a lot of modifications. I feel like this should be relatively simple in terms of thinking. To put it simply: split the number into integers and decimals and perform multiplication operations separately, and then put the result into an array of a specific length. When putting it in, you need to calculate the offset position of the storage, and finally process this ( Carry, mark, etc.) to get the final result. Are you a little dizzy? Please let me explain in detail: First, you have to split the numbers into integers + decimals, and then use (x1+x2) (y1+y2) = x1y1+x1y2+x2y1+x2y2. Calculated in this way, it becomes an integer operation. Much simpler. But how to add up the…
A complete case of using Java to implement product search, addition, shipment and storage operations
The example in this article describes the operations of searching, adding, exporting and warehousing goods in Java. Share it with everyone for your reference, the details are as follows: package com.jredu.oopch08; public class Goods1 { private int id; private String name; private double price; private String uom; private int balance; public Goods1(int id, String name, double price, String uom, int balance) { super(); this.id = id; this.name = name; this.price = price; this.uom = uom; this.balance = balance; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getUom() { return uom; } public void setUom(String uom) { this.uom = uom; } public int getBalance() { return balance; } public void setBalance(int balance) { this.balance = balance; } } package com.jredu.oopch08; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Scanner; import java.util.Set; public class TestGoods1 { private static Map map = new HashMap(); private static Scanner in = new Scanner(System.in); public static void get() { Goods1 goods1 = new Goods1(1001,…
JavaScript object attribute inspection, addition, deletion, access operation examples
Check Properties var mouse = { “name”: “betta”, “age”: 3, “varieties”: “milaoshu” } mouse.hasOwnProperty(“name”); // true mouse.hasOwnProperty(“sex”); //false Add attributes Define an object dog, then assign various attributes, then assign the color attribute, and finally traverse all attributes and values var dog={ name:”Mango”, type:”King of Clubs”, eat:function(){ alert(“eat”); } } Object.prototype.color=”white”; var name; for(name in dog){ document.write(name+” “+dog[name]+””) } The effect is as follows name mango type king of meetings eat function (){ alert(“eat”); } color white Delete attributes var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } delete cat.name; cat.sex = undefined; cat.color = null; alert(“Whether the name attribute exists:” + cat.hasOwnProperty(“name”)); //false alert(“Whether the sex property exists:” + cat.hasOwnProperty(“sex”)); //true alert(“whether the color property exists:” + cat.hasOwnProperty(“color”)); //true Access properties var cat = { “name”: “tom”, “sex”: “man”, “color”: “yellow” } var name1 = cat.name; //Access object properties through dot operator var name2 = cat[“name”]; //Access object properties through the bracket operator There are two ways to create objects var obj = new Object(); obj.name = “MangGuo”; obj.age = 25; var obj = { name: “MangGuo”, //name is the attribute name, “MangGuo” is the value age: 25 }
Addition, subtraction, multiplication, division, size comparison and usage precautions of BigDecimal in Java
Foreword To borrow words from the book “Effactive Java”, the main design goals of the float and double types are for scientific computing and engineering calculations. They perform binary floating-point operations, which are carefully designed to provide fast approximate calculations with high accuracy over a wide range of values. However, they do not provide completely accurate results and should not be used where accurate results are required. However, business calculations often require accurate results. In Java, the maximum value of int is: 2147483647. Now what if you want to use a number larger than this? In other words, the value is larger, so BigDecimal is used. There are many introductions to BigDecimal. Friends who need to know more can refer to this article: https://www.jb51.net/article/55395.htm 1. Addition, subtraction, multiplication and division of BigDecimal BigDecimal bignum1 = new BigDecimal(“10”); BigDecimal bignum2 = new BigDecimal(“5”); BigDecimal bignum3 = null; //addition bignum3 = bignum1.add(bignum2); System.out.println(“sum is: ” + bignum3); //Subtraction bignum3 = bignum1.subtract(bignum2); System.out.println(“The difference is: ” + bignum3); //Multiplication bignum3 = bignum1.multiply(bignum2); System.out.println(“The product is: ” + bignum3); //division bignum3 = bignum1.divide(bignum2); System.out.println(“Business is: ” + bignum3); The running result is: 2. Comparative size of BigDecimal. BigDecimal num1 = new BigDecimal(“0”); BigDecimal num2…
Summary of examples of common javascript array operation methods [connection, addition, deletion, deduplication, sorting, etc.]
The examples in this article describe common methods of operating Javascript arrays. Share it with everyone for your reference, the details are as follows: Run results: Interested friends can use Online HTML/CSS/Javascript code running tool: http://tools.jb51.net/code/HtmlJsRun to test the above code operation Effect. For more content related to Javascript, you can also check out the special topics on this site: “Summary of Javascript Array Operation Skills”, “Summary of Javascript Character and String Operation Skills”, “Summary of Javascript Traversal Algorithms and Skills”, “Summary of Javascript Mathematical Operation Usage” “, “Summary of Javascript Data Structure and Algorithm Techniques”, “Summary of Javascript Search Algorithm Techniques” and “Summary of Javascript Errors and Debugging Techniques” I hope this article will be helpful to everyone in Javascript programming.
3 ways to generate image verification codes in Java (letters, addition, subtraction, multiplication and division, Chinese)
The first method is composed entirely of letters and numbers package com.myFirstSpring.util; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.Random; import javax.imageio.ImageIO; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @Description Generate verification code * @author waa * @version V1.0, date 2011-7-4 */ public class ValidateCodeUtils extends HttpServlet { private static final long serialVersiOnUID= -1409007752285164213L; private static int width = 75; private static int height = 35; // private static char[] ch = // “AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789”.toCharArray(); private static char[] ch = “abcdefghijklmnopqrstuvwxyz0123456789”.toCharArray(); public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } // Generate a verification code of numbers and letters public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(“image/jpeg”); response.setHeader(“Pragma”, “No-cache”); response.setHeader(“Cache-Control”, “no-cache”); response.setDateHeader(“Expires”, 0); //Create image in memory BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // Get graphics context Graphics g = image.getGraphics(); // Generate random class Random random = new Random(); //Set background color g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); //Set font g.setFont(new Font(“Times New Roman”, Font.PLAIN, 18)); // draw borders // g.setColor(new Color()); // g.drawRect(0,0,width-1,height-1); // Randomly generate 155 interference…
Common date operations in Java (value acquisition, conversion, addition, subtraction, comparison)
In the development process of Java, it is inevitable to get entangled with the Date type. I am going to summarize the date-related operations frequently used in the project. JDK version 1.7. If it can help everyone save a few minutes to get up and move around and make a cup of coffee, it will be great. Okay, hehe. Of course, I only provide feasible solutions and do not guarantee best practices. Discussions are welcome. 1. Date value In the era of the old version of JDK, many codes used the java.util.Date class to obtain date values. However, since the Date class is not convenient for internationalization, in fact, starting from JDK1.1, it is more recommended to use java The .util.Calendar class handles time and date aspects. We won’t introduce the operations of the Date class here. Let’s go straight to the topic, how to use the Calendar class to obtain the current date and time. Since Calendar’s constructor method is protected, we will create a Calendar object through the getInstance method provided in the API. //There are multiple overloaded methods to create Calendar objects Calendar now = Calendar.getInstance(); //Default //Specify the time zone and region, or you can enter…