javascript - 使输入数字字段的最右边部分不可编辑

标签 javascript jquery css html

我想要这样的东西:

enter image description here

这里的%符号会默认出现在输入框内,无法编辑或删除。用户只能编辑 % 符号左侧的数字。当按下向上或向下箭头时,只有 % 符号左边的数字会增加或减少。

例如,如果我现在按向上箭头,它会显示

11%

,如果我按下箭头,它会显示

9%

我看过一些保持输入字段最左边部分不可编辑的示例,但在这里我需要最右边的部分不可编辑。

最佳答案

请看这个JSfiddle .我认为这会对您有所帮助。

<input id="edit_input" type="number"  style="width:80px;"></input>
<p>%</p>

input {
  float:left;
  font-size: 16px;
  padding: 0px 0 0px 0px;
  box-sizing:border-box;
}
p {
 margin:-4px 0px 0px -50px;
float:left;
padding-top: 5px;
cursor: default;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
 font-size: 20px;
}

关于javascript - 使输入数字字段的最右边部分不可编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43734259/

相关文章:

jquery - JqG​​rid colModel 动态格式化程序

javascript - jQuery - 忽略双重 AJAX 调用?

javascript - 如何从整数中切掉位

javascript - Bootstrap 3 : Triple nested tab error

javascript - 从 ng-template 访问范围

javascript - 如何在 ajaxStart 或 ajaxSend 中中止 AJAX 请求?

jquery - 文本效果 - 图像到 css/jQuery

css - 在没有 CSS 的情况下设置 html 文本的样式

css - 在 className `or` 语句中 react `if` 条件

javascript - JS尝试添加新的输入框和按钮