在網頁上隱藏影片標籤 - JavaScript
假設我們在網頁上有一個以下示例影片標籤
<video class="hideVideo" width="350" height="255" controls> <source src="" id="unique_video_id"> You cannot play video here...... </video>
若要隱藏網頁上的影片,請使用 yourVariableName.style.display=’none’。
示例
以下是程式碼 -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<style>
.hideVideo {
display: block;
z-index: 999;
margin-top: 10px;
margin-left: 10px;
}
</style>
<body>
<video class="hideVideo" width="350" height="255" controls>
<source src="" id="unique_video_id">
You cannot play video here......
</video>
</body>
<script>
var hideVideo = document.getElementsByClassName("hideVideo")[0];
hideVideo.style.display = "none";
</script>
</html>若要執行上述程式,請儲存檔名“anyName.html(index.html)”。右鍵單擊該檔案,然後在 Visual Studio Code 編輯器中選擇“使用 Live Server 開啟”選項。
輸出
這將在控制檯中產生以下輸出 -

在上面的示例輸出中,影片標籤已停用。如果你希望啟用,只需註釋掉上述行,即
//hideVideo.style.display = "none";
註釋掉上述行後,影片標籤將啟用,如下所示 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP