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浏览器下运行通过。。。。

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

Atom editor mac version download
The most popular open source editor
