选择的占位符值不会从默认值更改?

时间:2022-03-31 17:10:49

Im using the jquery plugin Chosen to mask a Html.Listbox as a muli selection tool. It works great except that I need to change the default text. I've tried setting the placeholder text both in the html and by way of jquery. Here is the relevant code...

我使用jquery插件Chosen来掩盖Html.Listbox作为muli选择工具。它工作得很好,除了我需要更改默认文本。我已经尝试在html和jquery中设置占位符文本。这是相关代码......

@Html.ListBox("Filter-Chooser",aList,new { @class = "chzn-select filter-chooser") 

function EnableMultiChoose() {
    $(".chzn-select").data("placeholder", "Filter By...");
    $(".chzn-select").chosen();
}

I've also tired specifying the parameter @placeholder = "Filter By ..." to no avail.I've checked the html output and it appears to set the placeholder property...

我也厌倦了指定参数@placeholder =“Filter By ...”无效。我检查了html输出,它似乎设置了占位符属性...

Html Rendered

Html呈现

<select class="chzn-select filter-chooser" id="Filter-Chooser" multiple="multiple" name="Filter-Chooser" placeholder="Filter By...">
<option value="Content">Content</option>
<option value="Author">Author</option>
<option value="DeckName">Deck Name</option>
...

Any ideas on how to specify the placeholder properly?

有关如何正确指定占位符的任何想法?

4 个解决方案

#1


10  

I will help: Use "data-placeholder" attribute.

我会帮忙:使用“data-placeholder”属性。

<select class="chzn-select filter-chooser" id="Filter-Chooser" multiple="multiple" name="Filter-Chooser" data-placeholder="Filter By...">

#2


4  

Okay, specify the placeholder via the data-placeholder attribute. cool.

好的,通过data-placeholder属性指定占位符。凉。

@Html.ListBox("Filter-Chooser", aList , new Dictionary<string,Object> { {"class","chzn-select   filter-chooser"}, {"data-placeholder","TEXT HERE"}})

#3


0  

If you're using simple_form you will need something like:

如果您使用的是simple_form,则需要以下内容:

<%= f.input :education_ids, :label => false, :collection => Education.all, :input_html => { :data => { :placeholder => 'Education' }} %>

#4


-2  

solution as below.

解决方案如下。

$("[value='Select Some Options']").val("your text");

#1


10  

I will help: Use "data-placeholder" attribute.

我会帮忙:使用“data-placeholder”属性。

<select class="chzn-select filter-chooser" id="Filter-Chooser" multiple="multiple" name="Filter-Chooser" data-placeholder="Filter By...">

#2


4  

Okay, specify the placeholder via the data-placeholder attribute. cool.

好的,通过data-placeholder属性指定占位符。凉。

@Html.ListBox("Filter-Chooser", aList , new Dictionary<string,Object> { {"class","chzn-select   filter-chooser"}, {"data-placeholder","TEXT HERE"}})

#3


0  

If you're using simple_form you will need something like:

如果您使用的是simple_form,则需要以下内容:

<%= f.input :education_ids, :label => false, :collection => Education.all, :input_html => { :data => { :placeholder => 'Education' }} %>

#4


-2  

solution as below.

解决方案如下。

$("[value='Select Some Options']").val("your text");