JS常用整理
取随机颜色
function bg1(){ return '#'+Math.floor(Math.random()*256).toString(10); } function bg2(){ return '#'+Math.floor(Math.random()*0xffffff).toString(16); } function bg3(){ var r=Math.floor(Math.random()*256); var g=Math.floor(Math.random()*256); var b=Math.floor(Math.random()*256); return "rgb("+r+','+g+','+b+")";//所有方法的拼接都可以用ES6新特性`其他字符串{$变量名}`替换 }可返回指定位置的字符。
var str="Hello world!";
document.write(str.charAt(0)); //charAt()方法可返回指定位置的字符。
//JavaScript 并没有一种有别于
// 字符串类型的字符数据类型,
// 所以返回的字符是长度为 1 的字符串
</script>
document.write(str.charAt(0)); //charAt()方法可返回指定位置的字符。
//JavaScript 并没有一种有别于
// 字符串类型的字符数据类型,
// 所以返回的字符是长度为 1 的字符串
</script>
blod to base64
var blobToBase64=function(blob, callback) {
var a = new FileReader();
a.onload = function(e) {
callback(e.target.result);
}
a.readAsDataURL(blob);
};
//使用方法,传入一个blob数据,在回调中接收处理成功的图片url
blobToBase64(blob, function(data) {
document.getElementById("scimg").value=data;
$('#gif').html('<img id="dwmoss" src="'+data+'"/><br><input type="button" name="button" id="button" value="分享图片" onclick="sbs()" class="btn btn-secondary radius size-MINI"/>');//预览
document.getElementById("tools_loading").style.display="none";
//$('#successimg img').attr('src', data);
});

浙公网安备 33010602011771号