首页 > 解决方案 > 如何根据其值隐藏下拉菜单中的选择选项 - wordpress

问题描述

我试图在由 wordpress 主题动态创建的下拉菜单中隐藏一个选项。这是我使用 jquery 的代码:

jQuery("#role option[value='cars']").hide();  // role is css ID of selection; cars is the value of an <option> of <select>

我将该代码放在一个文件中:/wp-content/themes/my-theme-child/custom-scripts/own-script.js,然后将以下代码插入到位于 my-theme-child 的 wordpress 的 functions.php 中/ 目录:

function add_custom_script() {
    wp_register_script('custom_script', home_url() . '/wp-content/themes/my-theme-child/custom-scripts/own-script.js', array( 'jquery' ));
    wp_enqueue_script('custom_script');
}  
add_action( 'wp_enqueue_scripts', 'add_custom_script' );

没有任何改变或工作。

你能给我一个正确的方向吗?

标签: jquerywordpress

解决方案


推荐阅读