<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">
????<title>javascript</title>
????<style?type="text/css">
????????body?{
????????????font-size:?12px;
????????}
????????
????????#txt?{
????????????height:?400px;
????????????width:?600px;
????????????border:?1px?solid?#333;
????????????padding:?5px;
????????}
????????
????????p?{
????????????line-height:?18px;
????????????text-indent:?2em;
????????}
????</style>
</head>
<body>
????<h2?id="con">JavaScript課程</h2>
????<div?id="txt">
????????<h5>JavaScript為網頁添加動態(tài)效果并實現與用戶交互的功能。</h5>
????????<p>1.?JavaScript入門篇,讓不懂JS的你,快速了解JS。</p>
????????<p>2.?JavaScript進階篇,讓你掌握JS的基礎語法、函數、數組、事件、內置對象、BOM瀏覽器、DOM操作。</p>
????????<p>3.?學完以上兩門基礎課后,在深入學習JavaScript的變量作用域、事件、對象、運動、cookie、正則表達式、ajax等課程。</p>
????</div>
????<form>
????????<input?type="button"?value="改變顏色"?onclick="color()">
????????<input?type="button"?value="改變寬度"?onclick="wid_height()">
????????<input?type="button"?value="隱藏內容"?onclick="none()">
????????<input?type="button"?value="顯示內容"?onclick="block()">
????????<input?type="button"?value="取消設置"?onclick="quxiao()">
????</form>
????<script?type="text/javascript">
????????function?color()?{
????????????var?yanse?=?document.getElementById("txt");
????????????yanse.style.color?=?"#fff";
????????????yanse.style.backgroundColor?=?"#333";
????????}
????????function?wid_height()?{
????????????var?kuangao?=?document.getElementById("txt");
????????????kuangao.style.width?=?"400px";
????????????kuangao.style.height?=?"600px";
????????}
????????function?none()?{
????????????var?yincang?=?document.getElementById("txt");
????????????yincang.style.display?=?"none";
????????}
????????function?block()?{
????????????var?xianshi?=?document.getElementById("txt");
????????????xianshi.style.display?=?"block";
????????}
????????function?quxiao()?{
????????????var?quxiao?=?confirm('是否取消設置');
????????????if?(quxiao?==?true)?{
????????????????var?quxiao?=?document.getElementById("txt");
????????????????quxiao.style.color?=?"#000";
????????????????quxiao.style.backgroundColor?=?"#fff";
????????????????quxiao.style.width?=?"600px";
????????????????quxiao.style.height?=?"400px";
????????????????quxiao.style.display?=?"block";
????????????}?else?{
????????????}
????????}
????</script>
</body>
</html>
2020-06-04
// 變量
? ? var objCon = document.getElementById('con');
? ? var objTxt = document.getElementById('txt');
變量可以定義在函數外面,只需要定義一次所有函數都可以使用
取消設置的函數可以這樣寫
//定義"取消設置"的函數
? ? function cancelSetUp()
? ? {
? ? ? ? let check;
? ? ? ? check = confirm();
? ? ? ? if(check==true)
? ? ? ? {
? ? ? ? ? ? objCon.removeAttribute("style");
? ? ? ? ? ? objTxt.removeAttribute("style");
? ? ? ? }
? ? }
希望有能幫到你
2020-06-02
盡可能避免拼音命名吧,好的代碼規(guī)范也是同樣重要的