A custom pop-up dialog code written in JavaScript_javascript skills
The picture below is my design idea
The following is the specific js code
1. First define several custom functions
Code
//Determine whether it is an array
function isArray(v)
{
return v && typeof v.length == 'number' && typeof v.splice == 'function';
}
//Create element
function createEle(tagName)
{
return document.createElement (tagName);
}
//Add child elements in body
function appChild(eleName)
{
return document.body.appendChild(eleName);
}
//Remove child elements from body
function remChild(eleName)
{
return document.body.removeChild(eleName);
}
2, Specific form implementation code
Code
//Pop-up window, title (html form), html, width, height, whether it is a modal dialog box (true, false), button (the close button is the default, the format is ['button 1', fun1 , 'Button 2', fun2] array form, the front is the button value, and the back is the button onclick event)
function showWindow(title,html,width,height,modal,buttons)
{
//Avoid Window is too small
if (width {
width = 300;
}
if (height {
height = 200;
}
//Declare the width and height of the mask (that is, the width and height of the entire screen)
var w,h;
//Visible area width and height
var cw = document .body.clientWidth;
var ch = document.body.clientHeight;
//The width and height of the body
var sw = document.body.scrollWidth;
var sh = document.body.scrollHeight ;
//The distance between the top of the visible area and the top and left side of the body
var st = document.body.scrollTop;
var sl = document.body.scrollLeft;
w = cw > sw ? cw :sw;
h = ch > sh ? ch:sh;
//Avoid the window being too large
if (width > w)
{
width = w;
}
if (height > h)
{
height = h;
}
//If modal is true, that is, a modal dialog box, a transparent mask must be created membrane
if (modal)
{
var mask = createEle('div');
mask.style.cssText = "position:absolute;left:0;top:0px;background:# fff;filter:Alpha(Opacity=30);opacity:0.5;z-index:10000;width:" w "px;height:" h "px;";
appChild(mask);
}
//This is the main form
var win = createEle('div');
win.style.cssText = "position:absolute;left:" (sl cw/2 - width/2) " px;top:" (st ch/2 - height/2) "px;background:#f0f0f0;z-index:10001;width:" width "px;height:" height "px;border:solid 2px #afccfe; ";
//Title bar
var tBar = createEle('div');
//afccfe,dce8ff,2b2f79
tBar.style.cssText = "margin:0;width:" width "px;height:25px;background:url(top-bottom.png);cursor:move;";
//The text part in the title bar
var titleCon = createEle('div');
titleCon.style.cssText = "float:left;margin:3px;";
titleCon.innerHTML = title;//firefox does not support innerText, so innerHTML is used here
tBar.appendChild(titleCon);
//"Close button" in the title bar
var closeCon = createEle('div');
closeCon.style.cssText = "float:right;width:20px;margin:3px;cursor:pointer; ";//cursor:hand is not available in firefox
closeCon.innerHTML = "×";
tBar.appendChild(closeCon);
win.appendChild(tBar);
//Form In the content part, overflow in CSS causes a scroll bar to appear when the content size exceeds this range.
var htmlCon = createEle('div');
htmlCon.style.cssText = "text-align:center; width:" width "px;height:" (height - 50) "px;overflow:auto;";
htmlCon.innerHTML = html;
win.appendChild(htmlCon);
//Form Bottom button part
var btnCon = createEle('div');
btnCon.style.cssText = "width:" width "px;height:25px;text-height:20px;background:url(top- bottom.png);text-align:center;padding-top:3px;";
//If the parameter buttons is an array, a custom button will be created
if (isArray(buttons))
{
var length = buttons.length;
if (length > 0)
{
if (length % 2 == 0)
{
for (var i = 0 ; i {
//Button array
var btn = createEle('button');
btn.innerHTML = buttons[i];//firefox The value attribute is not supported, so innerHTML is used here
// btn.value = buttons[i];
btn.onclick = buttons[i 1];
btnCon.appendChild(btn);
/ /User fills the space between buttons
var nbsp = createEle('label');
nbsp.innerHTML = "  ";
btnCon.appendChild(nbsp);
}
}
}
}
//This is the default close button
var btn = createEle('button');
// btn.setAttribute("value","close");
btn.innerHTML = 'Close';
// btn.value = 'Close';
btnCon.appendChild(btn);
win.appendChild(btnCon);
appChild(win );
/*************************************The following is the drag form event******** *************/
//X coordinate of the mouse stay
var mouseX = 0;
//Y coordinate of the mouse stay
var mouseY = 0;
//The distance from the form to the top of the body
var toTop = 0;
//The distance from the form to the left side of the body
var toLeft = 0;
//Determine whether the form can be moved
var moveable = false;
//Mouse down event of the title bar
tBar.onmousedown = function()
{
var eve = getEvent();
moveable = true ;
mouseX = eve.clientX;
mouseY = eve.clientY;
toTop = parseInt(win.style.top);
toLeft = parseInt(win.style.left);
//Move mouse event
tBar.onmousemove = function()
{
if(moveable)
{
var eve = getEvent();
var x = toLeft eve.clientX - mouseX;
var y = toTop eve.clientY - mouseY;
if (x > 0 && (x width 0 && (y height {
win.style.left = x "px";
win.style.top = y "px";
}
}
}
//Put down the mouse event, note that this is document instead of tBar
document.onmouseup = function()
{
moveable = false;
}
}
// Method to get browser events, compatible with IE and Firefox
function getEvent()
{
return window.event || arguments.callee.caller.arguments[0];
}
/ /Close event of the "Close Button" in the top title bar and bottom button bar
btn.onclick = closeCon.onclick = function()
{
remChild(win);
remChild( mask);
}
}
Instance call
str = "Look at the effect of my form";
showWindow('My prompt box',str,850,250,true,['region',fun1,'mineral type ',fun2]);
More complete and practical code, including definition and calling
code
请选择矿种:" addCheckbox('all','全(不)选','class_all','selectAll(this,"class_cb")') " | |||||||||
" addCheckbox('class_cb','铋','class_cb1') " | " addCheckbox('class_cb','钒','class_cb2') " | " addCheckbox('class_cb','金','class_cb3') " | " addCheckbox('class_cb','煤','class_cb4') " | " addCheckbox('class_cb','锰','class_cb5') " | " addCheckbox('class_cb','钼','class_cb6') " | " addCheckbox('class_cb','铅','class_cb7') " | " addCheckbox('class_cb','石膏','class_cb8') " | " addCheckbox('class_cb','石煤','class_cb9') " | " addCheckbox('class_cb','锑','class_cb10') " |
" addCheckbox('class_cb','铁','class_cb11') " | " addCheckbox('class_cb','铜','class_cb12') " | " addCheckbox('class_cb','钨','class_cb13') " | " addCheckbox('class_cb','锡','class_cb14') " | " addCheckbox('class_cb','锌','class_cb15') " | " addCheckbox('class_cb','银','class_cb16') " | " addCheckbox('class_cb','萤石','class_cb17') " | " addCheckbox('class_cb','铀','class_cb18') " | " addCheckbox('class_cb','稀土氧化物','class_cb19') " | " addCheckbox('class_cb','重晶石','class_cb20') " |
" addCheckbox('class_cb','硼','class_cb21') " | " addCheckbox('class_cb','磷','class_cb22') " | " addCheckbox('class_cb','水泥灰岩','class_cb23') " | " addCheckbox('class_cb','熔剂灰岩','class_cb24') " | " addCheckbox('class_cb','冶金白云岩','class_cb25') " | " addCheckbox('class_cb','岩盐','class_cb26') " | " addCheckbox('class_cb','芒硝','class_cb27') " | " addCheckbox('class_cb','钙芒硝','class_cb28') " | " addCheckbox('class_cb','地下水','class_cb29') " | " addCheckbox('class_cb','地下热水','class_cb30') " |
showWindow('我的提示框',str,850,250,true,['地区',fun1,'矿种',fun2]);
}
function selectAll(obj,oName)
{
var checkboxs = document.getElementsByName(oName);
for(var i=0;i
checkboxs[i].checked = obj.checked;
}
}
function getStr(cbName)
{
var cbox = document.getElementsByName(cbName);
var str = "";
for (var i=0;i
if(cbox[i].checked)
{
str = "," cbox[i].value;
}
}
str = str.substr(1);
return str;
}
function fun1()
{
var str = getStr('cities_cb');
alert('你选择的地区为:' str);
}
function fun2()
{
var str = getStr('class_cb');
alert('你选择的矿种为:' str);
}
此脚本在ie,firefox浏览器下运行通过。。。。

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor