Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính muted của Video trong HTML DOM


Thuộc tính muted của đối tượng Video trong HTML DOM trả về hoặc thiết lập giá trị boolean cho biết âm thanh của video có bị tắt hay không.

Cú pháp

Trả về giá trị boolean – true/false:

mediaObject.muted

Thiết lập muted thành booleanValue:

mediaObject.muted = booleanValue

Ở đây, "booleanValue" có thể là:

booleanValue Chi tiết
true Định nghĩa video sẽ có âm thanh tắt
false Định nghĩa video sẽ không có âm thanh tắt

Ví dụ

Ví dụ minh họa thuộc tính Video muted:

<!DOCTYPE html> <html> <head> <title>HTML DOM Video muted</title> <style>    * {       padding: 2px;       margin:5px;    }    form {       width:70%;       margin: 0 auto;       text-align: center;    }    input[type="button"] {       border-radius: 10px;    } </style> </head> <body>    <form>       <fieldset>          <legend>HTML-DOM-Video-muted</legend>          <video id="demo" width="320" controls><source    src="https://www.tutorialspoint.com/html5/foo.mp4" type="video/mp4"></video><br>          <input type="button" onclick="getTrackDetails(1)" value="Ban ngày">          <input type="button" onclick="getTrackDetails(2)" value="Ban đêm">          <div id="divDisplay">          </div>       </fieldset>    </form> <script>    var divDisplay = document.getElementById("divDisplay");    var demo = document.getElementById("demo");    function getTrackDetails(val) {       if(val === 1){          demo.muted = false;          divDisplay.textContent = 'Đang ban ngày, không ai bị phiền';       }       else{          demo.muted = true;          divDisplay.textContent = 'Đang ban đêm, video sẽ tắt âm theo mặc định';       }    } </script> </body> </html>

Kết quả

Nhấn nút „Ban đêm“:

Thuộc tính muted của Video trong HTML DOM

Nhấn nút „Ban ngày“:

Thuộc tính muted của Video trong HTML DOM