


js prompt information jtip encapsulation code, which can be a picture or article_javascript skills
By the way, I changed my career to front-end, so I do some div css and the like every day. Today I will talk about using js to implement a title or alt function similar to the A tag. As for the benefits of this function, please listen to me slowly. First of all, the prompts brought by the title or alt attributes are too simple, and the style It cannot be modified, and you have to move the mouse over the element and wait for 1 to 3 seconds before it is displayed. The content is only simple text, and html content cannot be added. So, to sum up, I have to encapsulate a js prompt box of my own. Maybe you will say, doesn’t jquery have a jtip component? Yes, that means your thinking is quite avant-garde. If you're used to it, then use it. Who wouldn't use it anyway? I just gave this small example for everyone to study.
First of all, what we have to do is to clarify our thinking. This should be the case in everything we do. Don’t start writing code as soon as we get something. We must first think about what we want to get, and then pay for it. This is just like falling in love. You can't always think about getting the other person without thinking of ways to give. Well, it's a bit far-fetched. What we want to get is a brand new prompt box. It can be very simple or very complex. It should be able to cover everything, which is easy to think of div. Then I also hope that when my mouse moves to a certain label, it will appear near the mouse in time and disappear when it moves away. It's that simple. Now that my thinking is clear, don't you think it was such an easy thing before? Well, fools can be taught! Now that the idea is clear, let’s implement it step by step according to this idea.
First create a DIV, hide it, and add all the styles you want to it. The code is as follows:
var tipdiv = document.createElement("div");
tipdiv.id = "txbtip";
tipdiv.style.position = "absolute";
tipdiv.style.padding = "3px";
tipdiv .style.background = "#565656";
tipdiv.style.zIndex = "999";
tipdiv.style.border = "1px solid #000";
tipdiv.style.background = "# F4F8FC";
tipdiv.style.fontsize = "14px";
var rootEle = document.body || document.documentElement;
rootEle.appendChild(tipdiv);
Then add the onmousemove event and onmouseout event to the label to be added. For the sake of greater commonality, here I give all the labels to be added a common class name (txbtip).
var txbtip = getElementsByClassName('txbtip', 'input');>
function getElementsByClassName(n, tag) {
tag = tag || "*";
var classElements = [], allElements = document.getElementsByTagName(tag);
for (var i = 0; i n = "" n "";
var cn = " " allElements[i].className " ";
if (cn.indexOf(n) != -1) {
classElements[classElements.length] = allElements[i];
}
}
return classElements;
}
Note: This method is to get the set of certain tags with class n.
for (var tip in txbtip) {
var temp = "";
txbtip[tip].onmouseover = function(e) {
tipdiv.style.display = "block";
var title = this.title;
temp = this.title;
this.title = "";//The reason for doing this here is to clear the original title prompt.
tipdiv.innerHTML = title;
setTipPosition(e);//This method is used to position the tip box.
}
txbtip[tip].onmousemove = function(e) {
setTipPosition(e);//This method is used to position the prompt box.
}
txbtip[tip].onmouseout = function(e) {
//alert("out");
this.title = temp;
temp = "";
tipdiv.style.display = "none";
}
The last step is to position the label, which is the setTipPotion method that appeared above. Its specific implementation is as follows :
function setTipPosition(e) {
e = e || event;
tipdiv.style.left = e.clientX 10 'px';
var top = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
tipdiv .style.top = e.clientY 10 top 'px';
}
Now that we are almost done, we can then reverse it and combine it with page binding. So write it into window.onload.
window.onload=function(){...}
However, in this case, it is possible that a page will have multiple window.onload events and lead to failure, so some work needs to be done. Moreover, the corresponding label of the prompt box just now may already have a mouse event, and a judgment must be added.
if (window.addEventListener) { window.addEventListener("load", ready, false); } else if (window.attachEvent) { window.attachEvent("onload", ready); }
The following is the complete code
jstip.js
[code]
//******js text prompt txb20100119********/
if (window.addEventListener) {
window. addEventListener("load", ready, false);
} else if (window.attachEvent) {
window.attachEvent("onload", ready);
}
function ready( ) {
var txbtip = getElementsByClassName('txbtip', '*');
var tipdiv = document.createElement("div");
tipdiv.id = "txbtip";
tipdiv. style.position = "absolute";
tipdiv.style.padding = "3px";
tipdiv.style.background = "#565656";
tipdiv.style.zIndex = "999";
tipdiv.style.border = "1px solid #000";
tipdiv.style.background = "#F4F8FC";
tipdiv.style.fontsize = "14px";
tipdiv.style.display = "none";
var rootEle = document.body || document.documentElement;
rootEle.appendChild(tipdiv);
for (var tip in txbtip) {
//alert(txbtip[tip ].id);
var temp = "";
txbtip[tip].onmouseover = function(e) {
tipdiv.style.display = "block";
var title = this. title;
temp = this.title;
this.title = "";
tipdiv.innerHTML = title;
setTipPosition(e);
//alert(title);
}
txbtip[tip].onmousemove = function(e) {
setTipPosition(e);
}
txbtip[tip].onmouseout = function(e) {
//alert ("out");
this.title = temp;
temp = "";
tipdiv.style.display = "none";
}
}
function getElementsByClassName(n, tag) {
tag = tag || "*";
var classElements = [], allElements = document.getElementsByTagName(tag);
for (var i = 0 ; i n = "" n "";
var cn = " " allElements[i].className " ";
if (cn.indexOf(n) != -1) {
classElements[classElements.length] = allElements[i];
}
}
return classElements;
}
function setTipPosition(e) {
e = e || event;
tipdiv.style.left = e.clientX 10 'px';
var top = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
tipdiv.style.top = e.clientY 10 top 'px';
}
}
[code]

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools
