我想在表单中不显示任何选项
HTML:<option class="level-0" value="top-10-villen-de">Top-10-Villen</option>
jQuery:if(jQuery('option').attr('value') == 'top-10-villen-de'){
jQuery(this).css('display', 'none');
}
我的if语句有问题,但是我不知道问题在哪里。
有人能帮帮我吗?
谢谢。
隐藏下拉选项不兼容所有浏览器
我有更好的选择。wrap
将选项转换成span,当你需要它时,unwrap
它
提琴链接:http://jsfiddle.net/xms2uydx/
您使用了错误的this查看this Scope
http://jsfiddle.net/kevalbhatt18/r2m2ucgv/2/
上面的例子是给你两者之间的区别。1. 它来自于Jquery。2. 这是jquery函数的内部。
- 所以你可以在例子中看到第一个控制台i。e console.log(this)将返回窗口对象。
2。$(this)在click函数中会给你不同的值它与你的按钮相关它会给你按钮作用域
也可以用
jQuery("选项");(.level-0) . css("显示","没有一个")如果你知道option的类