parseint

vue v-model属性

半腔热情 提交于 2019-11-29 19:09:46
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <script src="../vue.js" type="text/javascript" charset="utf-8"></script> 7 </head> 8 <body> 9 <div id="app"> 10 <input type="text" v-model="n1"> 11 <select v-model="opt"> 12 <option value="+">+</option> 13 <option value="-">-</option> 14 <option value="*">*</option> 15 <option value="/">/</option> 16 </select> 17 <input type="text" v-model="n2"> 18 <input type="button" value="=" v-on:click="calca"> 19 <input type="text" v-model="result"> 20 </div> 21 </body> 22 <script type="text/javascript"> 23 var vm = new Vue({

js_数字处理。

你离开我真会死。 提交于 2019-11-29 18:51:45
// 1.只保留整数部分(丢弃小数部分) parseInt(5.1234);// 5 // 2.向下取整(<= 该数值的最大整数)和parseInt()一样 Math.floor(5.1234);// 5 // 3.向上取整(有小数,整数就+1) Math.ceil(5.1234); // 4.四舍五入(小数部分) Math.round(5.1234);// 5 Math.round(5.6789);// 6 // 5.绝对值 Math.abs(-1);// 1 // 6.返回两者中的较大值 Math.max(1,2);// 2 // 7.返回两者中的较小值 Math.min(1,2);// 1 // 随机数(0-1) Math.random(); 来源: https://www.cnblogs.com/wush-1215/p/11526909.html

模仿弹幕效果

寵の児 提交于 2019-11-29 16:06:00
最近公司在做直播,需要一个弹幕效果,就是那种飞来飞去的,所以写了一个,有借鉴别人的部分,望见谅,希望对大家有帮助 <!DOCTYPE> <html> <head> <meta charset="utf-8"> <title>弹幕</title> <style> *{ margin: 0; padding:0; } .container{ width:100%; height:100%; background-color: #f2f2f2; } .barrageBtn{ position: absolute; bottom:0px; padding: 5px 0px; height: 50px; width:100%; background-color: #f3f3f3; } .words{ width: 60%; float: left; height:35px; padding: 5px; margin-top: 5px; border: 1px solid #000; border-radius: 5px; outline: none; margin-left: 5px; } .btn{ float: left; width:120px; height: 37px; margin-left: 15px; border-radius: 5px; background-color:

Difference between int and int received by ParseInt in java

醉酒当歌 提交于 2019-11-29 14:16:55
int i = 0; int k = Integer.parseInt("12"); int j = k; System.out.println(i+1 + " " + j+1); Strangely the output received is 1 121 I can not figure out this basic difference. Please help me. Use brackets as follows System.out.println((i+1) + " " + (j+1)); From the docs The + operator is syntactically left-associative, no matter whether it is later determined by type analysis to represent string concatenation or addition. In some cases care is required to get the desired result. For example, the expression: a + b + c is always regarded as meaning: (a + b) + c Extending this to your scenario i+1

Checking if a variable is an integer in javascript

落花浮王杯 提交于 2019-11-29 14:15:48
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 one help? This is an answer to question mentioned in the topic, not the actual one in the body of the

Java: Comparing ints and Strings - Performance

有些话、适合烂在心里 提交于 2019-11-29 13:28:52
I have a String and an int, lets say: String str = "12345"; and int num = 12345; . What is the fastest way of seeing if they are the same, str.equals("" + num) or num == Integer.parseInt(str) (Or is there a faster way?)? This is the source code for Integer.parseInt and String.equals num == Integer.parseInt(str) is going to faster than str.equals("" + num) str.equals("" + num) will first convert num to string which is O(n) where n being the number of digits in the number. Then it will do a string concatenation again O(n) and then finally do the string comparison. String comparison in this case

Strange behaviour with spliting a string in Javascript

。_饼干妹妹 提交于 2019-11-29 11:01:45
I am trying to do something relatively simple. I have a date in this format dd/MM/yyyy eg: var newDate = "‎11‎/‎06‎/‎2015"; And I want to convert it to a date. This code only works in Chrome and Firefox: new Date(newDate) In IE11 I get Nan So I am trying to do this: var parts = newDate.split("/"); var year = parts[2].trim(); var month = parts[1].trim(); var day = parts[0].trim(); var dt = new Date(Number(year), Number(month) - 1, Number(day)); Which should work, but I have encountered a very strange bug. If you try this code: function myFunction() { var newDate = "‎11‎/‎06‎/‎2015"; var parts =

05.data-type

让人想犯罪 __ 提交于 2019-11-29 08:36:15
title date 数据类型 2019-08-18 JavaScript | 数据类型 关于某些数据类型进行一些特性的介绍以及常用方法介绍。 目录摘要 基本类型方法 数字 Number parseInt 和 parseFloat 舍入方法 常量 字符串 String 查找子串 获取子串 基本类型方法 基本类型 是原始类型中的一种值。 在 JavaScript 中有 6 种基本类型: string 、 number 、 boolean 、 symbol 、 null 和 undefined 。 对象类型 能够存储多个值作为属性。 可以使用大括号 {} 创建对象 基本类型作为对象 除了null和undefined的基本类型可以调用一些方法,此时会临时创建一个包装对象,提供额外的功能,用完即销毁。实现“轻量级”特性。 如: str.toUpperCase() 、 num.toFixed(n) 、 num.toString(base) 数字 Number 科学记数法简写 10000 可以写作 1e4 其他进制 十六进制 0x 、八进制 0o 、二进制 0b ,其他进制使用parseInt转化为十进制。 parseInt 和 parseFloat 对于日常情况,我们经常遇到非纯数字的字符串,为了优雅地从中提取数字,可以使用 parseInt 和 parseFloat 函数 alert (

扁平化数组,多维数组变一维数组

蓝咒 提交于 2019-11-29 06:12:04
//把多维数组转化为一维数组 var myarray1 = [[1,2,3],[4,5,6]] function flatten(arr) { return arr.join(',').split(',').map(function (item) { return parseInt(item); }) } var b=flatten(myarray1); console.log(b); arr.join(',')123456将数组转化为字符串 arr.join(',').split(',') split() 方法用于把一个字符串分割成字符串数组。["1","2","3","4","5","6"] arr.join(',').split(',').map(function (item) {    return parseInt(item);      [1,2,3,4,5,6] }) 来源: https://www.cnblogs.com/cycczh/p/11458497.html

js 抛物线、随机颜色

泄露秘密 提交于 2019-11-29 06:06:23
div:nth-of-type(1){ width: 600px; height: 2px; background: #000; position: absolute; top: 300px; } div:nth-of-type(2){ width: 2px; height: 600px; background: #000; position: absolute; left: 300px; } span{ display: block; position: absolute; width:2px; height:2px; background: #000; } <div></div> <div></div> <script> for(var x = -300; x <= 300; x++){ var y = -0.003 * Math.pow(x,2); document.write('<span style="top:'+ (y + 300) +'px;left:'+ (x + 300) +'px;"></span>'); } </script> //随机颜色 // function randomColor(){ // var // r = parseInt(Math.random() * 256).toString(16).length < 2 ? "0" + parseInt