面向对象,继承,浏览器,上传文件, ajax
2024-10-13 06:00:58
'use strict';
//父类
class Student2{
constructor(name){
this.name = name || 'tom';
}
hello(){
console.log('hello '+ this.name + '!');
}
}
var xiao = new Student2("jack");
xiao.hello(); //子类继承父类
class PrimaryStudent2 extends Student2{
constructor(name,grade){
super(name); // 记得用super调用父类的构造方法!
console.log(this);
this.grade = grade;
this.name = name;
}
mygrade(){
console.log(this.name +' at grade '+ this.grade);
}
}
var primary = new PrimaryStudent2('jack' ,'2');
primary.mygrade();
primary.hello();//调用父类的方法
navigator 对象表示浏览器的信息,最常用的属性包括: navigator.appName:浏览器名称;
navigator.appVersion:浏览器版本;
navigator.language:浏览器设置的语言;
navigator.platform:操作系统类型;
navigator.userAgent:浏览器设定的User-Agent字符串。
location http://www.example.com:8080/path/index.html?a=1&b=2#TOP
location.protocol; // 'http'
location.host; // 'www.example.com'
location.port; // '8080'
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'
要加载一个新页面,可以调用location.assign()。如果要重新加载当前页面,调用location.reload()方法非常方便。 if (confirm('重新加载当前页' + location.href + '?')) {
location.reload();
} else {
location.assign('/discuss'); // 设置一个新的URL地址
}
图片上传并显示
var fileInput = document.getElementById('test-image-file'),
info = document.getElementById('test-file-info'),
preview = document.getElementById('test-image-preview');
// 监听change事件:
fileInput.addEventListener('change', function () {
// 清除背景图片:
preview.style.backgroundImage = '';
// 检查文件是否选择:
if (!fileInput.value) {
info.innerHTML = '没有选择文件';
return;
}
// 获取File引用:
var file = fileInput.files[0];
// 获取File信息:
info.innerHTML = '文件: ' + file.name + '<br>' +
'大小: ' + file.size + '<br>' +
'修改: ' + file.lastModifiedDate;
if (file.type !== 'image/jpeg' && file.type !== 'image/png' && file.type !== 'image/gif') {
alert('不是有效的图片文件!');
return;
}
// 读取文件:
var reader = new FileReader();
reader.onload = function(e) {
var
data = e.target.result; // 'data:image/jpeg;base64,/9j/4AAQSk...(base64编码)...'
preview.style.backgroundImage = 'url(' + data + ')';
};
// 以DataURL的形式读取文件:
reader.readAsDataURL(file);
});
---恢复内容结束---
最新文章
- 一个简单的统计图像主颜色的算法(C#源代码)
- vb.net中常用键值
- 无法找到脚本引擎Jscript解决
- oralce11g 注冊表卸载20140810
- js后缀判断
- Hadoop运行中遇到的错误调试
- Javascript的精华
- Uva 12436 Rip Van Winkle&;#39;s Code
- iOS 如何优化 App 的启动时间
- 使用Dreamweaver正则表达式替换href中的内容
- 自定义view实现阻尼效果的加载动画
- spring cloud 容错之zuul回退和Zuul过滤器
- mysql基础常用命令
- ACM-ICPC 2018 沈阳赛区网络预赛 J Ka Chang
- JVM 自带性能监测调优工具 (jstack、jstat)及 JVM GC 调优
- POJ 2538
- linux系统挂载ISO文件
- Hashtable之Properties
- Problem C: 查找最大元素
- MySql 基础 基本使用方法