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)

#crash #ios4 #iphone #objective-c #uipickerview






관련 질문

WebView가 전체 활동을 죽이고 있습니다 --- 이것을 어떻게 디버깅 할 수 있습니까? (WebView killing the whole activity --- How can I debug this?)

연결 시도 시 Windows의 MySQL이 충돌함 (MySQL on Windows crashes on connection attempts)

휘발성 멤버는 멤버 함수에서 액세스할 수 없습니다. (volatile member can not be accessed by member function)

Ruby에서 Gosu로 텍스트를 인쇄할 수 없음(충돌) (Cannot print a text with Gosu in Ruby (crash))

이 기능은 .exe를 충돌시킵니다. 제가 뭘 잘못하고 있습니까? (This function makes the .exe crash, what am I doing wrong?)

PyAudio로 웨이브를 재생하는 Tkinter 버튼 호출 기능 - 충돌 (Tkinter button calling function to play wave with PyAudio -- crashes)

phonegap 카메라가 앱 충돌 (phonegap camera crashes the app)

대화 상자를 표시하려고 할 때 앱이 충돌함 (App crashed when try to display dialog box)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

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

새 줄이 발견되지 않으면 fget이 NULL을 반환하지 않습니다. (fgets dont return NULL when no new line found)

webview가 검은 색으로 바뀌고 응용 프로그램이 충돌합니다. (webview turns black and application crashes)







코멘트