jquery - 如何根据其值隐藏下拉菜单中的选择选项 - 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' );
没有任何改变或工作。
你能给我一个正确的方向吗?
解决方案
推荐阅读
- javascript - 如何确定“chart.js”插件服务中的图表类型
- python - 如何使用 python 自动给出正在运行的 linux 程序命令?
- javascript - 如何在不丢失任何数据的情况下防止双重表单提交?
- javascript - 用于操作 Facebook 图像的 Javascript 代码在控制台中有效,但在扩展中无效
- checkmarx - 使用 Checkmarx 扫描硬编码密码
- python - Python + JIRA API:按电子邮件地址将用户添加到组
- reactjs - 翻译成反应节点
- android - React Native gradlew bundleRelease 和 run-android --variant=release 制作不同的 APK
- python - 是否可以使用 float16 使用 tensorflow 1 进行训练?
- reactjs - Fetch-mock 在版本 3.2.0 redux-api-middleware 测试中不起作用