替换keyup上的符号

时间:2017-01-14 05:41:40

标签: javascript jquery html

我偶然发现了一个问题我不明白为什么会发生这种情况(不工作)。

我要做的只是取代1的金额值,出于某种原因我不能大声笑。

当用户输入金额时,如果他输入“,”,我必须将其更改为“。”即时 - 生活。

以下是样本..

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<input type="text" class="form-amount" id="textare" value="" placeholder="0.1 BTC - 10 BTC" />
int

2 个答案:

答案 0 :(得分:2)

这是因为您在更改其值后未设置文本框的值。请参阅以下工作代码:

$(document).ready(function() {
    // Uberfix Amount
    $(".form-amount").keyup(function() {		
        var $this = $(this), amount = $this.val();
        $this.val(amount.replace(",", "."));
        console.log('passed');
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<input type="text" class="form-amount" id="textare" value="" placeholder="0.1 BTC - 10 BTC" />

答案 1 :(得分:0)

您计算了修改后的字符串,但未将其设置回字段。如果我理解你的问题,这对你有用:

for link in soup.find_all("a"):
    if 'http' in link['href']:       
        print link['href']          
$(document).ready(function() {
    // Uberfix Amount
    $(".form-amount").keyup(function() {
        var amount = $(".form-amount").val();
        $(".form-amount").val(amount.replace(",", "."));
        alert('passed');
    });
});

请注意,<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <input type="text" class="form-amount" id="textare" value="" placeholder="0.1 BTC - 10 BTC" />获取值,而.val()将字段值设置为指定的字符串。