jQuery从中删除选择的选项 [英] jQuery remove selected option from this

查看:100
本文介绍了jQuery从中删除选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里发表第一篇文章,我很安心:)我进行了搜索,但找不到我想要的.

first post here, I come in peace :) I've searched but can't quite find what I'm after.

我正在尝试操纵选择框的选定选项.有人可以解释一下为什么这样吗:

I am trying to manipulate the selected option of a select box. Can someone please explain why this works:

$('#some_select_box').click(function() {
  $('#some_select_box option:selected').remove();
});

但这不是:

$('#some_select_box').click(function() {
  $('this option:selected').remove();
});

我只想使用"this"而不是拼写选择框的ID-有人可以为我指出正确语法的正确方向吗?这让我发疯,因为它看起来应该非常简单.而且我敢肯定,这是对某人而不是我的帮助,因为一天结束了,我很烦……任何指针都值得赞赏.

I just want to use "this" instead of spelling out the id of the select box - can someone point me in the right direction for the correct syntax? It's driving me mad because it looks like it should be really simple. And I'm sure it is to someone, but not me, cos its the end of the day and I'm brain-fried... Any pointers much appreciated.

欢呼

推荐答案

this不是CSS选择器. 您可以通过将this的id作为上下文传递来避免拼写:

this isn't a css selector. you can avoid spelling the id of this by passing it as a context:

$('option:selected', this).remove();

http://api.jquery.com/jQuery/

这篇关于jQuery从中删除选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆