如何在输入标签中对货币进行静态标记 [英] How to make a static sign of a currency in the input tag

查看:83
本文介绍了如何在输入标签中对货币进行静态标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望当我使用Tab键专注于输入标签时,它不应突出显示$符号,而应使其保持静态并让用户键入该值,并且如果用户希望将其保留为空白,则将其保留为空白应该显示其占位符以及静态的$符号.

I want that when I focus on the input tag using tab key, it should not highlight the $ sign and instead keep it static and let the user type the value, and also if user wants to leave it blank then it should show its placeholder along with the static $ sign.

这是我正在尝试的标记:

This is the markup I'm trying:

 <div style="width: 40%; float: right;">                    
    <input id="value" type="text" name="value" placeholder="$ Value" value="" required="required" onfocus="this.placeholder = '$ ', this.value='$ '" onblur="this.placeholder = '$ Value'" />
 </div>

推荐答案

如果您一直需要使用$号,并且颜色相同,我会分别放置$号:

I would place $ sign separately if you need it all the time and in same color:

<div style="width: 40%; float: right;">    
    <span style="border: 1px solid black; color:grey"> $
        <input id="value" type="text" style="border: none; outline: 0" name="value" placeholder="Value" value="" required="required"/>
    </span>
</div>

我也有一个在输入中带有$符号的变体,但是在这种情况下,当激活时它将变色为黑色:

I also have a variant with $ sign inside input, but in that case it will change color to black when active:

<div style="width: 40%; float: right;">
    <input id="value" type="text" name="value" placeholder="$ Value" value="" required="required" onfocus="if(this.value == '') this.value='$ '" onblur="if(this.value == '$ ') this.value = ''" />
</div>

这篇关于如何在输入标签中对货币进行静态标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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