亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

嘗試運行 JavaScript 函數時出現對象錯誤的空值

嘗試運行 JavaScript 函數時出現對象錯誤的空值

PHP
梵蒂岡之花 2023-06-24 18:07:34
這是我第一次在這里發帖,我對編碼還比較陌生,所以請原諒我的無知。我正在為我的 WordPress 模板開發一個頁面,該頁面將在單擊 div 時打開一個模式窗口以顯示圖像。這是到目前為止我的 HTML..<?php/*** Template Name: Home Page*/get_header(); ?><div class="grid-container"><?php$args = array('post_type' => 'artists',);$the_query = new WP_Query( $args );if ( $the_query->have_posts() ) :   while ( $the_query->have_posts() ) :       $the_query->the_post();       ?>       <?php $postId = get_the_ID(); ?>      <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>      <div id="popup">      <img id="myImg" src="wp-content/themes/dollarartclub/images/women.png" alt="Snow" style="width:100%;max-width:300px">    </div><!-- modal -->    <div id="mymodal" class="modal">      <span class="close">&times;</span>      <img class="modal-content" id="img01">     <div id="caption"></div>    </div>      </article>       <?php   endwhile;endif;wp_reset_query();    ?>  </article></div>Javascript(在我的functions.php中排隊)jQuery(document).ready(function($) {var modal = document.getElementById("myModal");var img = document.getElementById("myImg");var modalImg = document.getElementById("img01");var captionText = document.getElementById("caption");img.onclick = function(){  modal.style.display = "block";  modalImg.src = this.src;  captionText.innerHTML = this.alt;}var span = document.getElementsByClassName("close")[0];span.onclick = function() {  modal.style.display = "none";}});我不斷收到控制臺錯誤“未捕獲的 TypeError:無法訪問屬性“樣式”,模態為空”我收到“無法訪問 onclick,img 為空”,但將 javascript 包裝在 jquery 函數中似乎可以阻止此操作。我已經嘗試讓它工作一周了,但沒有成功,這讓我發瘋。任何幫助將不勝感激。謝謝你!
查看完整描述

1 回答

?
慕斯王

TA貢獻1864條經驗 獲得超2個贊

你的選擇器是不同的,一個有一個大寫的M。

<div id="mymodal" class="modal">
document.getElementById("myModal")


查看完整回答
反對 回復 2023-06-24
  • 1 回答
  • 0 關注
  • 120 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號