2017-10-12 61 views
2

我有一個小的JavaScript文件(alg-wSelect.js),它只有一行代碼: jQuery('select.alg-wselect')。wSelect(); 它由wordpress插件調用。 是否有可能將它添加到另一個JavaScript文件或包含它內聯? 我該怎麼做? 預先感謝您如何內嵌或包含JavaScript文件

+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遺漏的類型錯誤:jQuery的(...) .wSelect不是函數 at alg-wSelect.js:1 – its4yougr

+0

我認爲你需要先閱讀這個函數的文檔。你應該知道什麼是「句柄」,什麼是「版本」被引用。正如你已經解釋過的,你需要添加文件「alg-wSelect.js」中的小腳本。所以你不需要排隊,你需要使用內聯js函數和任何已經入隊的js文件來添加代碼。 – Tristup

相關問題