onkeyup="this.value = this.value.replace(/,/g,'.

onkeyup="this.value = this.value.replace(/,/g,'.')" with php echo' '

本文关键字:this value quot onkeyup replace      更新时间:2023-09-26

在输入字段中,需要将,替换为.

有了HTM,这样的代码就可以工作onkeyup="this.value = this.value.replace(/,/g,'.')"

但需要在php中使用(带有echo),如下所示:

echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,'.')" style="width:53px;"></input>';

使用php不起作用。如果使用此this.value.replace(/,/g,/./),则,将替换为/./

尝试了(/,/g,"/./")(/,/g,/"."/)(/,/g,.),但都不起作用(我的意思是,不会更改为.)。

有什么想法吗?

您必须在PHP代码中用反斜杠转义'

echo '<input type="text" name="amount_1" onkeyup="this.value = this.value.replace(/,/g,''.'')" style="width:53px;"></input>';

否则,你就把你的绳子剪成图片,然后把它和要点放在一起。