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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17258337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:40:36  来源:igfitidea点击:

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

phpjavascript

提问by user2465936

In input field need to replace ,with ..

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

With HTM such code is working onkeyup="this.value = this.value.replace(/,/g,'.')"

使用 HTM 这样的代码正在工作 onkeyup="this.value = this.value.replace(/,/g,'.')"

But need to use in php (with echo) like this:

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

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

With php does not work. If use this this.value.replace(/,/g,/./)then ,is replaced with /./.

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

Tried (/,/g,"/./"), (/,/g,/"."/), (/,/g,.)nothing works (I mean ,does not change to .).

试过(/,/g,"/./")(/,/g,/"."/)(/,/g,.)实在不行(我的意思是,不改变.)。

Any ideas?

有任何想法吗?

回答by idmean

You have to escape the 'with a backslash in your PHP code.

您必须'在 PHP 代码中使用反斜杠进行转义。

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

Otherwise you are cuting your string into to pices an put it together with the point.

否则,您将把您的绳子切成小块并将其与尖端放在一起。