You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Input type="number"及TextBoxFor中的增减箭头?

Removing Number Input Arrows for TextBoxFor and Standard <input type="number">

Got it, let's fix those pesky up/down arrows on number inputs—especially since you're using them for phone numbers where those controls don't serve any practical purpose. Here's how to handle both scenarios:

1. Removing Arrows from TextBoxFor (ASP.NET MVC)

First, make sure your TextBoxFor helper is rendering an <input type="number"> (you might need to explicitly set the type if it's not inferred). Then, use CSS to target the spin buttons across all major browsers.

Step 1: Add the CSS class

Add this CSS to your stylesheet to hide the arrows:

/* Hide number input spin buttons across browsers */
.no-spin::-webkit-inner-spin-button,
.no-spin::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.no-spin::-moz-number-spin-box {
    -moz-appearance: textfield;
}

/* For legacy IE support (optional, since IE is rarely used now) */
.no-spin {
    -ms-appearance: none;
}

Step 2: Apply the class to TextBoxFor

When rendering your input, add the no-spin class to the HTML attributes:

@Html.TextBoxFor(m => m.PhoneNumber, new { @type = "number", @class = "form-control no-spin" })

2. Removing Arrows from Standard <input type="number">

This uses the exact same CSS approach—just apply the no-spin class directly to the input element:

<input type="number" class="no-spin" placeholder="Enter your phone number" />

Pro Tip for Phone Numbers

Since you're using this input for phone numbers, consider switching to <input type="tel"> instead. It:

  • Automatically brings up a numeric keyboard on mobile devices
  • Doesn't show spin buttons by default
  • Still supports numeric input validation if needed

Example:

<input type="tel" placeholder="Enter your phone number" />

内容的提问来源于stack exchange,提问作者Victor Zyon Tiangson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:10:19