parseint

js笔记(强制类型转换)

微笑、不失礼 提交于 2020-01-09 16:42:55
这篇随笔记录一下js中数据的各种类型转换的规则,虽然很基础,但是重新过一遍会发现有些规范还是挺意想不到的 首先介绍一下ToString, ToNumber, ToBoolean 的转换规则 1、ToString    规则1:null 转换为 “null” , undefined 转换为 “undefined” , true 转换为 “true” ;   规则2:普通对象,除非自定义,否则用 toString();       数组的toString()方法,先把所有单元字符串化,然后再用“,”连接;[1,2,3,4] // “1,2,3,4”; 2、ToNumber   规则1:布尔值 true 转换为 1, false 转换为 0; undefined 转换为 NaN; null 转换为 0;字符串处理失败时返回NaN;   规则2:以 0开头地十六进制数会被当成十进制;   规则3:对象会先被处理成相应地基本类型值,再按照值类型做相应处理;        对象做ToPrimitive操作规则:先valueOf(), 如果valueOf的结果不是基本类型,再进行 toString() ;如果均不返回基本类型,则报TypeError;       使用Object.create(null) 创建的对象,无valueOf 跟 toString 方法,故不能被强制类型转换   规则4

vue倒计时

99封情书 提交于 2020-01-08 20:47:00
export default { name : "HelloWorld" , data ( ) { return { endTime : "2020-01-10 19:00:00" , day : "" , hour : "" , min : "" , second : "" } ; } , created ( ) { this . getReserTime ( ) ; } , methods : { dateFormate ( num ) { if ( num < 10 ) { return '0' + num } else { return num } } , getReserTime ( ) { let interval = setInterval ( ( ) => { let nowTime = new Date ( ) . getTime ( ) ; let endTime = new Date ( this . endTime ) . getTime ( ) ; let chaTime = ( endTime - nowTime ) / 1000 ; this . day = parseInt ( chaTime / ( 60 * 60 * 24 ) ) ; this . hour = parseInt ( ( chaTime % ( 60 * 60 * 24 ) )

Converting String Mac Address to Hex

泄露秘密 提交于 2020-01-06 07:56:14
问题 I am trying to convert a string macaddress to hex value. I got a C# code which does the same thing but when I use the java code it gives me negative values. as in the C# code returns signed integer but how do i do the same in Java following is part of my code Integer hex = Integer.parseInt(MacAddress.subString(0,2), 16 ); MacAddress[0] = hex.byteValue(); i get something like 148 on the c# code and java returns -148 how can I sort this out thanks UPDATE and I just realised that my c# code

js加解密

时间秒杀一切 提交于 2020-01-04 03:28:23
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>字符串加密</title> </head> <body> <script language="JavaScript"> <!-- Begin function encrypt(str, pwd) { if (pwd == null || pwd.length <= 0) { alert("Please enter a password with which to encrypt the message."); return null; } var prand = ""; for (var i = 0; i < pwd.length; i++) { prand += pwd.charCodeAt(i).toString(); } var sPos = Math.floor(prand

漂亮的JS日历控件

耗尽温柔 提交于 2020-01-04 02:20:47
代码如下: <script> /* alin */ /* Email:caoailin111@sohu.com */ /* QQ:38062022 */ /* Creation date: 2004-6-13 */ var myC_x,myC_y; var myC_timeset=null,myC_timeset1=null; var divObj=null; var inputName; function myCalendar() //构建对象 { var myDate = new Date(); this.year = myDate.getFullYear(); this.month = myDate.getMonth()+1; this.date = myDate.getDate(); this.format="yyyy-mm-dd"; this.style = myStyle(1);  this.show = createCalendar; this.input = createInput; } function myStyle(num) //设置样式 { if(!num||isNaN(num)){alert('参数不对,采用默认样式!');num=1;}  var style = new Array(); style[1]=".week{background-color:

Checking if a variable is an integer in javascript

有些话、适合烂在心里 提交于 2019-12-29 08:47:05
问题 I made a form where the user inputs values for width and height that they want for the pop up window to be. I am using window.open for that. So I think I need to check if the values for width and height are integer. I have a function that checks that a variable is an integer that is... function isInteger(possibleInteger) { return !isNaN(parseInt(possibleInteger)); } but I don't know how to call this function to the width and height function to check if the user inputted an integer. Can any

JavaScript parseInt is giving me wrong number, what I'm doing wrong?

折月煮酒 提交于 2019-12-29 01:51:05
问题 So, for parseInt('10152547376283911', 10) I'm expecting 10152547376283911, but I'm getting 10152547376283912. What I'm doing wrong? 回答1: Javascript native numbers do not have enough precision (significant digits) to hold the number you are expecting. See the question What JavaScript library can I use to manipulate big integers? for suggestions on how to deal with this problem. Depending on your application, you may actually be able to use strings instead of numbers (for example, if your

常用JS方法整理

*爱你&永不变心* 提交于 2019-12-29 01:04:54
本篇目录: 1.截取指定字节数的字符串 2.判断是否微信 3.获取时间格式的几个举例 4.获取字符串字节长度 5.对象克隆、深拷贝 6.组织结构代码证验证 7.身份证号验证 8.js正则为url添加http标识 9.URL有效性校验方法 10.自定义jsonp方法 11.cookie操作 12.生成随机字符串 (可指定长度) 13.浏览器判断 14.Rem移动端适配 15.获取url后参数 16.动态加载JS 17.生成随机颜色值 上述方法都是日常工作中使用所得,所以会不定时更新,大家也可以留下你觉得好的方法:) 1.截取指定字节数的字符串 /** * 截取指定字节的字符串 * @param str 要截取的字符穿 * @param len 要截取的长度,根据字节计算 * @param suffix 截取前len个后,其余的字符的替换字符,一般用“…” * @returns {*} */ function cutString(str, len, suffix) { if (!str) return ""; if (len <= 0) return ""; if (!suffix) suffix = ""; var templen = 0; for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) > 255) {

常用JS方法整理

本小妞迷上赌 提交于 2019-12-29 01:03:58
本篇目录: 1.截取指定字节数的字符串 2.判断是否微信 3.获取时间格式的几个举例 4.获取字符串字节长度 5.对象克隆、深拷贝 6.组织结构代码证验证 7.身份证号验证 8.js正则为url添加http标识 9.URL有效性校验方法 10.自定义jsonp方法 11.cookie操作 12.生成随机字符串 (可指定长度) 13.浏览器判断 14.Rem移动端适配 15.获取url后参数 16.动态加载JS 17.生成随机颜色值 上述方法都是日常工作中使用所得,所以会不定时更新,大家也可以留下你觉得好的方法:) 1.截取指定字节数的字符串 /** * 截取指定字节的字符串 * @param str 要截取的字符穿 * @param len 要截取的长度,根据字节计算 * @param suffix 截取前len个后,其余的字符的替换字符,一般用“…” * @returns {*} */ function cutString(str, len, suffix) { if (!str) return ""; if (len <= 0) return ""; if (!suffix) suffix = ""; var templen = 0; for (var i = 0; i < str.length; i++) { if (str.charCodeAt(i) > 255) {

Vue---基于v-model的简易计算器

时光怂恿深爱的人放手 提交于 2019-12-28 04:07:02
<input type="text" v-model="n1"> <select name="" id="" v-model="opt"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" v-model="n2"> <input type="button" value="=" @click="calc"> <input type="text" v-model="result"> data () { return { msg: '猥琐发育,别浪~', n1: 0, n2: 0, result: 0, opt: '+' } } calc: function(){ switch(this.calc){ case '+': this.result = parseInt(this.n1)+ parseInt(this.n2); break; case '-': this.result = parseInt(this.n1)- parseInt(this.n2); break; case '*': this.result = parseInt(this