WordPress에서 Simple Jquery Click이 작동하지 않음 (Simple Jquery Click not working in WordPress)


문제 설명

WordPress에서 Simple Jquery Click이 작동하지 않음 (Simple Jquery Click not working in WordPress)

저는

.

javascript 파일을 바닥글에 포함했습니다.

내 자바스크립트 코드는

jQuery( document ).ready(function($) {
 console.log( "ready!" );
 $("#start‑reading").click(function() {
  console.log("click");
 });

});

한 번의 jQuery 클릭 기능. 여기 콘솔에서 ready 메시지를 볼 수 있습니다. 그러나 ID가 start‑reading인 요소를 클릭하면 아무 일도 일어나지 않습니다.

여기에 마크업이 있습니다.

<button id="start‑reading">
</button>

저는 wordpress를 처음 사용합니다. 제가 잘못하고 있는 wordpress realted가 있습니까? 이것은 WordPress가 아닌 환경에서 작동해야 하기 때문입니다.


참조 솔루션

방법 1:

WP makes sure it only loads scripts once. So it collects all script requests from all plugins and decides the correct order based on dependencies and priority.

To correctly add your script in WordPress you need to use wp_enqueue_script().

방법 2:

Keep use jQuery instead of $. Just like the below code.

     jQuery(document).ready(function() {
          console.log( "ready!" );
         jQuery("#start‑reading").click(function() {
                console.log("click");
          });

     });

Check your element ID whether it's #start‑reading

Or #start_reading.

방법 3:

Use the recommended way, add these code to functions.php

function your_theme_scripts() {

    wp_enqueue_script( 'your‑theme‑script', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), '', true );

}

add_action( 'wp_enqueue_scripts', 'your_theme_scripts' );

jQuery is already integrated to WordPress, now you can wirte jQuery code to the script.js file.

방법 4:

If it is a dynamically added button (e.g. during the execution of some code), you can use onclcick in the HTML code of the button.


jQuery('#parent')
    .html('<button onclick="test_func()">Test</button>');

BUT the declaration of the target function ( test_func() ) must be in the root of the file (not function in function)

(by SoorajtaoKvvaradhaNasir AhmedAnar Salimkhanov)

참조 문서

  1. Simple Jquery Click not working in WordPress (CC BY‑SA 2.5/3.0/4.0)

#geometry #3d #equation #ellipse #math






관련 질문

이미지를 사용하지 않고 Nx2 행렬에서 원의 반지름을 어떻게 찾을 수 있습니까? (How could I find the radius of a circle in a Nx2 matrix, not using images)

d3.js의 궤도 유형 차트 (Orbit type chart in d3.js)

원의 둘레에 스프라이트 추가 (Add a sprite on circumference of a circle)

Java: 질량 중심을 중심으로 삼각형 회전 (Java: Rotate triangle around mass center)

값이 없는 경우 HTML5 로컬 저장소 개체는 무엇을 반환합니까? (What does the HTML5 Local Storage object return if there is no value?)

WordPress에서 Simple Jquery Click이 작동하지 않음 (Simple Jquery Click not working in WordPress)

직사각형 필드 내에서 다양한 크기의 직사각형을 효율적으로 배치 (Efficient placement of variable size rectangles within a rectangular field)

{'northeast': {'lat':}, 'southwest': {'lat': }}(Google 지도) Python에서 다각형을 만드는 방법 (How to create Polygon out of {'northeast': {'lat':}, 'southwest': {'lat': }} (google maps) Python)

실린더 슬라이스를 따라 두 점 사이의 SVG 경로 호를 계산하는 방법 (How to calculate SVG path arc between two points along the slice of a cylinder)

make_solid() PostGIS를 사용하여 꼭짓점 테이블에서 polyhedralsurfaceZ 생성 (Create polyhedralsurfaceZ from vertex table with make_solid() PostGIS)

시작/끝 각도 문제가 있는 OpenGL 타원 (OpenGL Ellipse with start/end angle issues)

2D 그리드의 두 선분이 인접하는지 테스트하는 알고리즘 (Algorithm to test if two line segments on a 2d grid are adjacent)







코멘트