Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery在引导的SelectPicker中搜索文本_Jquery_Twitter Bootstrap_Bootstrap Select - Fatal编程技术网

使用jQuery在引导的SelectPicker中搜索文本

使用jQuery在引导的SelectPicker中搜索文本,jquery,twitter-bootstrap,bootstrap-select,Jquery,Twitter Bootstrap,Bootstrap Select,我想在下拉列表中搜索文本,并将其设置为按文本选择。这是我的控件 HTML: 我正在使用引导选择器。我可以在代码中使用contain:还是selectpicker有自己的方法 更新: 我尝试了简单的选择控制,它正在工作…这里是对于那些需要解决相同情况的人,我像这里一样解决了它 var userToSearchFor = "Jadaf"; $("#area_location_id").find("option:contains('" + userToSearchFor +"')") .each(fu

我想在下拉列表中搜索文本,并将其设置为按文本选择。这是我的控件

HTML:

我正在使用引导选择器。我可以在代码中使用contain:还是selectpicker有自己的方法

更新:


我尝试了简单的选择控制,它正在工作…这里是

对于那些需要解决相同情况的人,我像这里一样解决了它

var userToSearchFor = "Jadaf";
$("#area_location_id").find("option:contains('" + userToSearchFor +"')")
.each(function ()   {
 $(this).attr("selected", "selected");
});

$('#area_location_id').selectpicker('val', userToSearchFor );
$('#area_location_id').selectpicker('refresh');

下面的答案有一点变化

var userToSearchFor = "text to search";
var selectedID;
$("#area_location_id").find("option:contains('" + userToSearchFor +"')")
    .each(function ()   {
        $(this).attr("selected", "selected");
        selectedID = $(this).val();
});

$('#area_location_id').selectpicker('val', selectedID );
$('#area_location_id').selectpicker('refresh');
请注意,selectpickers值不能为st by attrselected,true
也可以通过选项值“不选择文本”来设置val。

您到底想要什么?我想根据传递的变量显示所选文本。在上述情况下,我想让它显示所选的“Al Furjan”
var userToSearchFor = "Jadaf";
$("#area_location_id").find("option:contains('" + userToSearchFor +"')")
.each(function ()   {
 $(this).attr("selected", "selected");
});

$('#area_location_id').selectpicker('val', userToSearchFor );
$('#area_location_id').selectpicker('refresh');
var userToSearchFor = "text to search";
var selectedID;
$("#area_location_id").find("option:contains('" + userToSearchFor +"')")
    .each(function ()   {
        $(this).attr("selected", "selected");
        selectedID = $(this).val();
});

$('#area_location_id').selectpicker('val', selectedID );
$('#area_location_id').selectpicker('refresh');