基础原生js

给input元素赋值显示,用value:

 let enwenInput = document.getElementById("enwenTex");
 enwenInput .value = "apple";
获取input元素填入的值:
let enwen = document.getElementById("enwenText").value;
 
获取selection标签选中的值:
let cixingSel = document.getElementById("wordClassSelect");
let cixing = cixingSel.options[cixingSel.selectedIndex].value;
获取selection标签下的所有option:

var obj=document.getElementById('mySelect');
var items=document.getElementById("sect").options;

设置selection标签选中的项:

var obj=document.getElementById('mySelect');

 obj.selectedIndex = 3;
 
给td标签,a标签,lable标签赋值显示,用innerHTML :
let td1 = document.createElement("td");
td1.innerHTML = wordList[i].english;
 
元素添加点击事件:
(1)直接加在属性上
<button onclick="updateWord()">
                        确 认
 </button>
(2)js添加
let elea = document.createElement("a");
elea.setAttribute("href", "#");
elea.setAttribute("id",  wordList[i].id);
elea.innerHTML = '编辑';
elea.onclick  = editFun;
function editFun(){}
 
点击后弹出确认框:
<button onclick="updateWord()">
                        确 认
 </button>
function updateWord{
  
  var res = confirm("确定删除该条记录吗?");
            if(res){
                alert("删除成功!");
                window.location.reload();
            }
}
原文地址:https://www.cnblogs.com/maycpou/p/13845490.html