String.prototype.trim = function()
{
return this.replace(/(^s*)|(s*$)/g, "");
}
String.prototype.len=function()
{
return this.replace(/[^x00-xff]/g,'aa').length;
}
function StringBuilder(value)
{
this.strings = new Array("");
this.append(value);
}
// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
if (value)
{
this.strings.push(value);
}
}
// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
this.strings.length = 1;
}
// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
return this.strings.join("");
}
//string format prototype
// sample: var test="my name is {0} {2} " ;
// alert(test.format('liang','zhonghua');
if (!String._FORMAT_SEPARATOR){
String._FORMAT_SEPARATOR = String.fromCharCode(0x1f);
String._FORMAT_ARGS_PATTERN = new RegExp('^[^' String._FORMAT_SEPARATOR ']*'
new Array(100).join('(?:.([^' String._FORMAT_SEPARATOR ']*))?'));
}
if (!String.format)
{
String.format = function (s){
return Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR).
replace(String._FORMAT_ARGS_PATTERN, s);
}
}
if (!''.format)
{
String.prototype.format = function (){
return (String._FORMAT_SEPARATOR
Array.prototype.join.call(arguments, String._FORMAT_SEPARATOR)).
replace(String._FORMAT_ARGS_PATTERN, this);
}
}
//end string format
function checkLoginByCookie()
{
var cookieId="AUTHTEST";
if(window.location.href.toLowerCase().indexOf("qidian.com") > -1)
{
cookieId="cmfuToken";
}
if((GetCookie(cookieId)!=null && GetCookie(cookieId).length > 0 ))
{
return true;
}
else
{
if(GetCookie('cmfu_al') != null && GetCookie('cmfu_al').length > 0)
{
return true;
}
}
return false;
}
function getUrlParam(name)
{
var reg = new RegExp("(^|&)" name "=([^&]*)(&|$)","i");
var r = window.location.search.substr(1).match(reg);
if (r!=null)
{
return unescape(r[2]);
}
else
{
return null;
}
}
function $(objName)
{
if(document.getElementById)
{
return document.getElementById(objName );
}
else if(document.layers)
{
return eval("document.layers['" objName "']");
}
else
{
return eval('document.all.' objName);
}
}
function DateAdd(BaseDate, interval, DatePart)
{
var dateObj = new Date(BaseDate.replace("-",","));
var millisecond=1;
var second=millisecond*1000;
var minute=second*60;
var hour=minute*60;
var day=hour*24;
var year=day*365;
var newDate;
var dVal = new Date(dateObj)
var dVal=dVal.valueOf();
switch(DatePart)
{
case "ms": newDate=new Date(dVal millisecond*interval); break;
case "s": newDate=new Date(dVal second*interval); break;
case "mi": newDate=new Date(dVal minute*interval); break;
case "h": newDate=new Date(dVal hour*interval); break;
case "d": newDate=new Date(dVal day*interval); break;
case "y": newDate=new Date(dVal year*interval); break;
default: return escape("日期格式不对");
}
newDate = new Date(newDate);
return newDate.getFullYear() "-" (newDate.getMonth() 1) "-" newDate.getDate() ;
}
//增加当前日期的天数
Date.prototype.AddDays=function (interval)
{
var dateObj = this;
var millisecond=1;
var second=millisecond*1000;
var minute=second*60;
var hour=minute*60;
var day=hour*24;
var year=day*365;
var newDate;
var dVal = new Date(dateObj)
var dVal=dVal.valueOf();
newDate=new Date(dVal day*interval);
newDate = new Date(newDate);
return newDate
}
function SetCookie(name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2].toGMTString() : (new Date()).AddDays(30).toGMTString();;
var path = (argc > 3) ? argv[3] : "/";
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
var content = name "=" escape(value) ";";
if(expires != null)
{
content = " expires=" expires ";";
}
if(path != null)
{
content = " path=" path ";";
}
if(domain != null)
{
content = " domain=" domain ";";
}
document.cookie = content;
}
function GetCookie(cookieName)
{
var cookieString = document.cookie;
var start = cookieString.indexOf(cookieName '=');
// The reason for adding the equal sign is to avoid having
// the same string as cookieName in some Cookie values.
if (start == -1) // Not found
return null;
start = cookieName.length 1;
var end = cookieString.indexOf('; ', start);
if (end == -1) return unescape(cookieString.substring(start));
return unescape(cookieString.substring(start, end));
}
/*Text box gets focus*/
function TextBoxOnFocus(txtControl,strDefaultText)
{
if (txtControl.value==strDefaultText)
txtControl.value="";
}
/*The text box loses focus*/
function TextBoxOnBlur(txtControl,strDefaultText)
{
if (txtControl.value.replace(/(^[s]*)|( [s]*$)/g,"")=="")
txtControl.value=strDefaultText;
}
/*Function: Pop-up group message window*/
function MultiSendWin(subject,content)
{
var win =window.open(uploadURL "?subject=" subject "&content=" content,"","menubar=no,width=480,height= 550,resizeable=no","");
return false;
}
/*Function: Pop-up message window
function SpaceSendMsg(toUserId)
{
var win =window.open(spaceSendMsgURL "?toUserId=" toUserId,"","menubar=no,width=500,height=400,resizeable=no","");
return false;
}
*/
function ShowServerMessage(result)
{
eval(result.value);
}
//Press enter to submit the form
function KeydownSubmitForm(btnId)
{
var btn=document.getElementById(btnId);
if (btn!=null&& event.keyCode== 13)
{
event.return Value= false;
event.keyCode=9;
btn.click();
}
}
//ReadChapter - Voucher js
function MDown(Object) {
Obj=Object.id
document.all(Obj).setCapture()
pX=event.x-document.all(Obj).style.pixelLeft;
pY=event.y -document.all(Obj).style.pixelTop;
}
function MMove(){
if(Obj!=''){
document.all(Obj).style .left=event.x-pX;
document.all(Obj).style.top=event.y-pY;
}
}
function MUp(){
if(Obj!=''){
document.all(Obj).releaseCapture();
Obj='';
}
}
//Close capture Coupon information
function LayerClose(divDiscount){
document.getElementById(divDiscount).style.visibility="hidden";
}
//Display coupon information
function LayerShow(divDiscount,discountPrize){
var prizeUI = document.getElementById(divDiscount);
prizeUI.style.left = screen.width-530;
prizeUI.style.top = screen.Height - 480 ;
prizeUI.style.visibility="visible";
document.getElementById("lblPrize1").innerHTML=discountPrize;
document.getElementById("lblPrize2").innerHTML=discountPrize;
window.setInterval("LayerClose('" divDiscount "')",15000);
}
//Help masterpage use
function HideMenu(menuid)
{
var obj = document.getElementById(menuid);
if(obj.style.display == "none")
{
obj.style.display = "";
}
else
{
obj.style.display = "none";
}
if(obj.style.display == "")
{
var tmpId = "M0";
for(var i = 1 ; i {
var myid = tmpId i;
if(myid != menuid)
{
document.getElementById(myid).style.display = "none";
}
}
}
}
/* div login */
function ShowLoginDiv()
{
var builder = new StringBuilder();
builder.append("
"); builder.append("登录"); builder.append(" | "); "); builder.append("×"); builder.append(" | ");
"); builder.append(""); builder.append(" | ");
//window.top.scrollTo(0,0);
document.getElementById("DivMask").style.height=document.body.scrollHeight;
document.getElementById("DivMask").style.width=document.body.scrollWidth;
document.getElementById("DivMask").style.display = 'block';
document.getElementById("DivLogin").style.display = "block";
document.getElementById("DivLogin").innerHTML = builder.toString();
ScrollDiv();
window.onscroll=ScrollDiv;
window.onresize=ScrollDiv;
window.onload=ScrollDiv;
}
function HideLoginMask()
{
document.getElementById("DivMask").style.display="none";
document.getElementById("DivLogin").style.display="none";
}
/*随屏幕滚动*/
function ScrollDiv()
{
if($("DivLogin"))
{
document.getElementById("DivLogin").style.top=(document.body.scrollTop
(document.body.clientHeight-document.getElementById("DivLogin").offsetHeight)/2) "px";
document.getElementById("DivLogin").style.left=(document.documentElement.scrollLeft
(document.body.clientWidth-document.getElementById("DivLogin").offsetWidth)/2) "px";
}
if($("AddMark"))
{
// if(!event )
// return;
$("AddMark").style.top=document.body.clientHeight document.body.scrollTop-200
$("AddMark").style.left=document.body.clientWidth-56;
$("AddMark").style.display='';
// (document.body.clientHeight-$("AddMark").offsetHeight)/2) "px";
if($("MonthVoteTip"))
{
//$("MonthVoteTip").style.top=document.body.scrollTop document.body.clientHeight-$("MonthVoteTip").offsetHeight "px";
$("MonthVoteTip").style.top = getPosition($("AddMark")).y - $("AddMark").offsetHeight "px";
}
}
}
function AutoScroll()
{
window.onscroll=ScrollDiv;
window.onresize=ScrollDiv;
window.onload=ScrollDiv;
}
function getPosition(el)
{
for (var lx=0,ly=0;el!=null;lx =el.offsetLeft,ly =el.offsetTop,el=el.offsetParent);
return {x:lx,y:ly}
}
/* 2007-11-28 XuJian */
//截取字符串 包含中文处理
//(串,长度,增加...)
function subString(str, len, hasDot)
{
var newLength = 0;
var newStr = "";
var chineseRegex = /[^x00-xff]/g;
var singleChar = "";
var strLength = str.replace(chineseRegex,"**").length;
for(var i = 0;i {
singleChar = str.charAt(i).toString();
if(singleChar.match(chineseRegex) != null)
{
newLength = 2;
}
else
{
newLength ;
}
if(newLength > len)
{
break;
}
newStr = singleChar;
}
if(hasDot && strLength > len)
{
newStr = "..."
}
return newStr; * 2007-10-26 14:20 문자열 길이 가져오기(한자 포함) */
function GetStringLength(strObj)
{
return strObj.replace(/[^x00-xff]/g," **").length;
}
function addMark(title,url) {
try{
if (window.sidebar) {
window.sidebar.addPanel(title) , url,"");
} else if( document.all ) {
window.external.AddFavorite( url, title)
} else if( window.opera && window.print ) {
return true;
}
}catch(e)
{
Alert("브라우저 보안 설정에서 이 작업을 허용하지 않습니다.")
}
}

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

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.


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

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.

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

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