2017-10-12 4 views
2

코드 한 줄만있는 작은 javascript 파일 (alg-wSelect.js)이 있습니다 : jQuery ('select.alg-wselect'). wSelect(); wordpress 플러그인에 의해 호출되었습니다. 다른 자바 스크립트 파일에 추가하거나 인라인을 포함 할 수 있습니까? 어떻게하면됩니까? 미리 감사드립니다.자바 스크립트 파일을 인라인 또는 포함하는 방법

+0

에서 함수를 읽으십시오. html로 귀하의 html로 – falloutx

+0

답장을 보내 주셔서 감사합니다! ! 나는 그것을 시도했지만 Uncaught TypeError : jQuery (...). wSelect (index) : 3054의 함수가 아닙니다! ! ! 어떻게 포함/추가 할 수 : jQuery ('select.alg-wselect'). wSelect(); 다른 .js 파일에? 즉 : wSelect.min.js 파일이 있습니다. jQuery ('select.alg-wselect')를 어떻게 추가 할 수 있습니까? wSelect(); 나는 그것을 새로운 라인에 넣었다. 잘 모르겠다 .... – its4yougr

답변

1

이것은 wp_add_inline_script를 사용하여 수행 할 수 있습니다. 코드를 검색 :

wp_enqueue_script('handel', 'JS FILE PATH' , array(), 'version', true); 
$integrate_script="jQuery('select.alg-wselect').wSelect()"; 
wp_add_inline_script('handel', esc_js($integrate_script)); 

는 이전에 대기열 스크립트 스크립트 인라인을 추가합니다 wp_add_inline_script. here

+0

답장을 보내 주셔서 감사합니다 ...... – its4yougr

+0

답장을 보내 주셔서 감사합니다 ...... 나는 functions.php에 추가했습니다 : wp_enqueue_script ('handel', '/ wp-content/plugins/currency-switcher-woocommerce/includes/js/alg-wSelect.js ', array(),'version ', true); $ integrate_script = "jQuery ('select.alg-wselect'). wSelect()"; wp_add_inline_script ('handel', esc_js ($ integrate_script)); 알지 못하는 SyntaxError : 유효하지 않거나 예기치 않은 토큰 jquery-migrate.min.js : 1 JQMIGRATE : 마이그레이션이 설치됨, 버전 1.4.1 alg-wSelect.js : 1 잡히지 않은 TypeError : jQuery (...) .wSelect가 함수가 아닙니다. at alg-wSelect.js : 1 – its4yougr

+0

이 함수에 대한 문서를 먼저 읽어야합니다. "핸들"과 "버전"이 무엇인지 알아야합니다. "alg-wSelect.js"파일에있는 작은 스크립트를 추가해야한다고 설명 했으므로. 따라서 대기열에 넣지 않아도됩니다. 이미 대기열에있는 js 파일과 함께 인라인 js 함수를 사용하여 코드를 추가해야합니다. – Tristup