最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to remove the clear text input X in bootstrap? - Stack Overflow

programmeradmin5浏览0评论

I have a form I've put together using Bootstrap 3. Some of the fields are for date input, and I'm using Bootstrap 3 Datepicker to pop up calendars. I have put onkeydown="return false;" on the input controls to prevent free text from being inserted.

The trouble is, users can still (and will) clear the text box with the little X that bootstrap puts in there. Is it possible to remove this functionality?

Here's the datepicker markup. It's enabled depending upon the index value of a drop down list. I'm using webforms:

<div class="col-sm-3">
    <div class='input-group date' id='dateEnd'>
    <asp:TextBox ID="datepickerEnd" runat="server" CssClass="form-control datepickerEnd" Enabled="False" placeholder="Specify to date" onkeydown="return false;" />
    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
    </span>
    </div>
</div>

I have a form I've put together using Bootstrap 3. Some of the fields are for date input, and I'm using Bootstrap 3 Datepicker to pop up calendars. I have put onkeydown="return false;" on the input controls to prevent free text from being inserted.

The trouble is, users can still (and will) clear the text box with the little X that bootstrap puts in there. Is it possible to remove this functionality?

Here's the datepicker markup. It's enabled depending upon the index value of a drop down list. I'm using webforms:

<div class="col-sm-3">
    <div class='input-group date' id='dateEnd'>
    <asp:TextBox ID="datepickerEnd" runat="server" CssClass="form-control datepickerEnd" Enabled="False" placeholder="Specify to date" onkeydown="return false;" />
    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
    </span>
    </div>
</div>
Share Improve this question edited Mar 3, 2015 at 12:42 Tom Pickles asked Mar 3, 2015 at 12:35 Tom PicklesTom Pickles 90011 silver badges28 bronze badges 5
  • Show your code to display this Datepicker – Reptar Commented Mar 3, 2015 at 12:37
  • So you're really trying to prevent the user from entering something that isn't a numeric date? Isn't there a better way to do that than disallowing all keyboard input? This bootstrap 3 demo doesn't have the 'X' FWIW; it's probably some script that runs on all inputs on your page that you'll need to add an exception to. – Rup Commented Mar 3, 2015 at 12:39
  • @bbvanee Code has been added. – Tom Pickles Commented Mar 3, 2015 at 12:42
  • This es in IE only. right? – Jitendra Pancholi Commented Mar 3, 2015 at 12:46
  • @JitendraPancholi Yes, I only just realised. IE8 is my target browser for this solution also. – Tom Pickles Commented Mar 3, 2015 at 12:48
Add a ment  | 

2 Answers 2

Reset to default 5

try below code

.clear::-ms-clear {
    display: none;
}

<input type="text" class="clear" />

Fiddle: http://jsfiddle/n57t00bh/ Check this in IE

The character is not inserted by Bootstrap, but by Internet Explorer from versions 10 and up. To remove the cross option, style your input using the ::ms-clear pseudo-selector.

::-ms-clear {
    display: none;
}
发布评论

评论列表(0)

  1. 暂无评论