简体   繁体   English

在输入字段jQuery中隐藏某个字符

[英]Hide a certain character in an input field jQuery

I am trying to hide a dollar sign in an input field. 我试图在输入字段中隐藏美元符号。 I am populating the input field with some values from buttons, so when you click on the button it will populate the field, but it is still showing the dollar sign still for some reason. 我正在使用按钮中的一些值填充输入字段,因此,当您单击按钮时,它将填充该字段,但是由于某些原因,它仍然显示美元符号。 Some help will be much appreciated. 一些帮助将不胜感激。

Thanks, 谢谢,

Here is my fiddle - http://jsfiddle.net/7Shzg/1/ and the code bellow 这是我的小提琴-http: //jsfiddle.net/7Shzg/1/和下面的代码

$('#amount').html($('#amount').html().replace("$",""));

$( "button" ).click(function() {
        var text = $( this ).text();
             $( "#amount" ).val( text );
            });

Try this : replace $ with empty space while reading text value. 尝试以下操作:在读取文本值时,用空白替换$ Also you got two element with same id in jsfiddle. 另外,您在jsfiddle中得到了两个具有相同ID的元素。 put id = "amount" for input box. 输入框输入id =“ amount”。

HTML : HTML:

<label>Sum:</label>
    <input type="text" id="amount" name="amount">

    <ul id="money"> 
          <li>$500</li>
          <li>$1000</li>
    </ul>

jQuery : jQuery的:

$( "#money li" ).click(function() {
   var text = $( this ).text().replace('$','');
   $( "#amount" ).val( text );
});

Working Demo 工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM