使用javascript / jquery将字符修复为文本输入框 [英] Fix a character to text input box using javascript/jquery

查看:129
本文介绍了使用javascript / jquery将字符修复为文本输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法将'美元符号''修复'到文本输入框,例如< input type =textvalue =$/> 但是不能删除默认值,因此无论用户输入什么,总会有$符号'prepending'输入。

I am looking for a way to 'fix' a dollar symbol $ to a text input box eg <input type="text" value="$" /> but make it not possible for the default value to be removed, so that whatever the user inputs, there is always a $ symbol 'prepending' input.

干杯

推荐答案

有可能出现 background-image ,但很难保持,并且不会对字体大小的变化做出反应,这使得它成为IMO不太理想的选择。

There is the possibility of a background-image but it's difficult to maintain, and doesn't react to font size changes, which makes it the less optimal choice IMO.

我的选择更好的方法是:

A better way in my opionion would be:


  • 在输入旁边放一个< span> $< / span> 在它之前,实际上。)

  • Put a <span>$</span> next to the input (before it, actually).

给它 position:relative;左:20px

然后$符号进入输入字段。

The $ sign then moves into the input field.

然后,输入输入字段 padding-left:24px

Then, give the input field padding-left: 24px.

Voilá! $符号位于输入字段中,不会遮挡任何内容,也无法删除。

Voilá! The $ sign is in the input field, does not obscure anything, and cannot be removed.

这篇关于使用javascript / jquery将字符修复为文本输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆