使用jQuery更改选项的文本 [英] Change the Text of a Option with jQuery

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

问题描述

如何使用jQuery更改选项的文本?

How can I change the text of an option with jQuery?

我想在选项中更改最新的最新版本是 < select> element。

I'd like to change Newest with Oldest in an option is a <select> element.

$('select option:contains("Newest")').changeText('Oldest');

.replaceWith 对我不起作用。

谢谢。

如果我的脚本如下所示:

If my script looks like this:

$('select option:contains("Newest")').text('Oldest');
$('select option:contains("Oldest")').text('Newest');

然后我取消了第一个脚本,但这不是我想要的。我有两个选项,一个是Newest,我想用Oldest代替,另一个是Oldest,我想用Newest代替。我怎样才能做到这一点?

Then I'm canceling out the first script, however, that isn't what I want. I have two options one that reads "Newest" which I'd like to replace with "Oldest" and one that reads "Oldest" which I'd like to replace with "Newest". How can I accomplish that?

推荐答案

你应该开始一个新问题,但这里是答案:

You should start a new question but here's the answer:

$('select option:contains("Newest")').text('TEMPEST');
$('select option:contains("Oldest")').text('Newest');
$('select option:contains("TEMPEST")').text('Oldest');

这篇关于使用jQuery更改选项的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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