Как задействовать HTML дисплей с помощью JavaScript

Загрузить PDFЗагрузить PDF

Вот несложный JavaScript-трюк, который помогает контролировать настройки дисплея. Мы установим дисплей элемента на ноль и затем используем функцию JavaScript, чтобы задействовать дисплей, когда пользователь кликает на что-нибудь другое.

  1. How.com.vn Русский: Step 1 Создайте контент (для задействования дисплея) в контейнере.
    <div id="content" style="display:block;">Это контент.</div>
  2. How.com.vn Русский: Step 2 Вставьте код JavaScript, чтобы изменить дисплей.
    <script type="text/javascript">function toggleContent() {  // Получите ссылку DOM  var contentId = document.getElementById("content");  // Задействуйте  contentId.style.display == "block" ? contentId.style.display = "none" : contentId.style.display = "block"; }</script>
  3. How.com.vn Русский: Step 3 Используйте делегат event handler, чтобы задействовать функцию.
    <button onclick="toggleContent()">Toggle</button>
    Реклама

Об этой статье

How.com.vn работает по принципу вики, а это значит, что многие наши статьи написаны несколькими авторами. При создании этой статьи над ее редактированием и улучшением работали, в том числе анонимно, 14 человек(а). Количество просмотров этой статьи: 3944.
Эту страницу просматривали 3944 раза.

Была ли эта статья полезной?

⚠️ Disclaimer:

Content from Wiki How Русский language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

Notices:
  • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
  • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
  • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
  • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

Реклама