基本
- hidden
可以为true或false,在js中可以直接修改为yes还是false,例如
<select hidden=true id="member"></select>
<script>
var memberSelect = document.getElementById("member");
memberSelect.hidden = false;
</script>
- 获取某一个控件
document.getElementById,例
var serviceAddress = document.getElementById("serviceAddress").value;
- 解决中文乱码
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- 打印数据到控制台
console.log("2122212");
select
- 清空所有选项
options.length=0,例如
var memberSelect = document.getElementById("member");
memberSelect.options.length=0;
- 添加选项
memberSelect.add(new Option(name,key));
- 读取现在所选择的内容的参数
var memberSelect = document.getElementById("member");
console.log(memberSelect.value);
- 手动切换选择
<select onchange="changeMember()" id="member"></select>
button
- 点击按钮的响应
<button type="button" onclick="getConfig()">获取配置信息</button>
输入框
- 对应控件的值
<input id="projectName" type="text" value="这个是显示出来的值" />
选择文件
<input type="file" accept="text/plain" />
其中accept标识对文件格式的显示,具体限制方式如下所示,源自 https://blog.csdn.net/emoven/article/details/54908077
*.ac3 | audio/ac3 | AC3 Audio |
*.asf | allpication/vnd.ms-asf | Advanced Streaming Format |
*.au | audio/basic | AU Audio |
*.css | text/css | Cascading Style Sheets |
*.csv | text/csv | Comma Separated Values |
*.doc | application/msword | MS Word Document |
*.dot | application/msword | MS Word Template |
*.dtd | application/xml-dtd | Document Type Definition |
*.dwg | image/vnd.dwg | AutoCAD Drawing Database |
*.dxf | image/vnd.dxf | AutoCAD Drawing Interchange Format |
*.gif | image/gif | Graphic Interchange Format |
*.htm | text/html | HyperText Markup Language |
*.html | text/html | HyperText Markup Language |
*.jp2 | image/jp2 | JPEG-2000 |
*.jpe | image/jpeg | JPEG |
*.jpeg | image/jpeg | JPEG |
*.jpg | image/jpeg | JPEG |
*.js | text/javascript, application/javascript | JavaScript |
*.json | application/json | JavaScript Object Notation |
*.mp2 | audio/mpeg, video/mpeg | MPEG Audio/Video Stream, Layer II |
*.mp3 | audio/mpeg | MPEG Audio Stream, Layer III |
*.mp4 | audio/mp4, video/mp4 | MPEG-4 Audio/Video |
*.mpeg | video/mpeg | MPEG Video Stream, Layer II |
*.mpg | video/mpeg | MPEG Video Stream, Layer II |
*.mpp | application/vnd.ms-project | MS Project Project |
*.ogg | application/ogg, audio/ogg | Ogg Vorbis |
application/pdf | Portable Document Format | |
*.png | image/png | Portable Network Graphics |
*.pot | application/vnd.ms-powerpoint | MS PowerPoint Template |
*.pps | application/vnd.ms-powerpoint | MS PowerPoint Slideshow |
*.ppt | application/vnd.ms-powerpoint | MS PowerPoint Presentation |
*.rtf | application/rtf, text/rtf | Rich Text Format |
*.svf | image/vnd.svf | Simple Vector Format |
*.tif | image/tiff | Tagged Image Format File |
*.tiff | image/tiff | Tagged Image Format File |
*.txt | text/plain | Plain Text |
*.wdb | application/vnd.ms-works | MS Works Database |
*.wps | application/vnd.ms-works | Works Text Document |
*.xhtml | application/xhtml+xml | Extensible HyperText Markup Language |
*.xlc | application/vnd.ms-excel | MS Excel Chart |
*.xlm | application/vnd.ms-excel | MS Excel Macro |
*.xls | application/vnd.ms-excel | MS Excel Spreadsheet |
*.xlt | application/vnd.ms-excel | MS Excel Template |
*.xlw | application/vnd.ms-excel | MS Excel Workspace |
*.xml | text/xml, application/xml | Extensible Markup Language |
*.zip | aplication/zip | Compressed Archive |
alert
alert("Problem retrieving XML data");
http请求数据
- get
var request = null;
function getConfig() {
var url = "http://www.baidu.com";
request = new XMLHttpRequest();
request.onreadystatechange = state_Change;
request.open("GET", url);
request.send(null);
}
function state_Change() {
if (request.readyState == 4) {// 4 = "loaded"
if (request.status === 200) {// 200 = OK
var uploadJson = JSON.parse(this.response);
}
else {
alert("Problem retrieving XML data");
}
}
}
js读取用户所选择的文件
var selectedFile = document.getElementById('crashFile').files[0];
//创建文件读取对象
var fileReader = new FileReader();
//文件载入成功
fileReader.onload = function () {
var fileResult = fileReader.result;
console.log(fileResult);
}
//载入文件
fileReader.readAsText(selectedFile);