admin管理员组

文章数量:1317909

I have a normal HTML select dropdown box

<select id="day" name="day">
<option value="0">All</option>
<option value="1">Mon</option>
<option value="2">Tue</option>
<option value="3">Wed</option>
<option value="4">Thu</option>
<option value="5">Fri</option>
</select>

But on occassion I want to make some options not clickable, e.g. the Text faded out slightly if possible, and then nothing to happen if the text/value is selected.

Anyone know how?

I'm writing my page in PHP.

I have a normal HTML select dropdown box

<select id="day" name="day">
<option value="0">All</option>
<option value="1">Mon</option>
<option value="2">Tue</option>
<option value="3">Wed</option>
<option value="4">Thu</option>
<option value="5">Fri</option>
</select>

But on occassion I want to make some options not clickable, e.g. the Text faded out slightly if possible, and then nothing to happen if the text/value is selected.

Anyone know how?

I'm writing my page in PHP.

Share Improve this question asked Dec 10, 2009 at 13:48 thegunnerthegunner 7,16334 gold badges97 silver badges144 bronze badges 2
  • 1 Oh. You want the options disabled, not the whole select box. I deleted my answer cause I misunderstood the question. – Vincent Ramdhanie Commented Dec 10, 2009 at 13:53
  • I had previosuly written a jQuery solution for this if that's acceptable. I Don't have a pure JS fix unfortunately. – Neil Aitken Commented Dec 10, 2009 at 14:36
Add a ment  | 

3 Answers 3

Reset to default 4

Simply give the option tag an attribute 'disabled'.

<select>
<option value="1" disabled>1</option>
<option value="2">2</option>
</select>

So in this example, 1 will be faded out and un-selectable but 2 will be selectable.

IE 6 requires javascript to disable an item. There is a bug that prevents it from disabling individual items.

See here for details on how to implement this so that it functions in IE6: http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

There is a javascript solution here

http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/

There is no way to do this in IE without a JS hack sadly.

本文标签: phpmake select box values faded outunclickableStack Overflow