jQuery:包含功能限制以完全匹配 [英] JQuery :contains function limit to exact match

查看:126
本文介绍了jQuery:包含功能限制以完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JQuery:contains函数来确定从SESSION变量中选择了哪个选项.

Using the JQuery :contains function to decide which option on a select is selected from a SESSION variable.

包含功能与错误的选项匹配,因为它们是"PADI开放水域潜水教练"和另一个"PADI开放水域潜水教练"的选择

The contains function is matching the wrong option as their is an option 'PADI Open Water' and another 'PADI Open Water Scuba Instructor'

我们如何限制它以匹配确切的内容而已?

How do we limit it to match the exact content and no more?

$('option:contains("<?php echo $_SESSION['divelevel'];?>")').attr('selected', 'selected');

推荐答案

尝试使用 .filter() ,找到所需的选项.

Try using .filter(), to find the option you want.

$('option').filter(function(){
    return $(this).html() == "<?php echo $_SESSION['divelevel'];?>";
}).attr('selected', 'selected');

这篇关于jQuery:包含功能限制以完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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