代碼運(yùn)行問題
完整且空間時(shí)間復(fù)雜度最小的代碼,供大家借鑒,有疑問可以一起交流 ? ??
?<!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="CC()"> ?
? ? <input type="button" value="改變寬高" onclick="CS()">
? ? <input type="button" value="隱藏內(nèi)容" onclick="hide()">
? ? <input type="button" value="顯示內(nèi)容" onclick="show()">
? ? <input type="button" value="取消設(shè)置" onclick="cennel()">
? </form>
? <script type="text/javascript">
? ? var p1=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function CC(){
? ? p1.style.color="red";
? ? p1.style.backgroudColor="#CCC";
}
//定義"改變寬高"的函數(shù)
function CS(){
? ? p1.style.width="400px";
? ? p1.style.height="400px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function hide(){
? ? p1.style.display="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function show(){
? ? p1.style.display="block";
}
//定義"取消設(shè)置"的函數(shù)
function cennel(){
? ? var p2=confirm("是否取消設(shè)置");
? ? if(p2==true)
? ? {
? ? ? ? p1.removeAttribute("style");
? ? }
}
? </script>
</body>
</html>
2018-02-08
謝分享