最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - onkeyup="this.value = this.value.replace(,g,'.')" with php echo' &#39

programmeradmin1浏览0评论

In input field need to replace , with ..

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

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

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 /./.

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

Any ideas?

In input field need to replace , with ..

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

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

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 /./.

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

Any ideas?

Share Improve this question edited Jun 23, 2013 at 6:48 user2465936 asked Jun 23, 2013 at 6:44 user2465936user2465936 1,0404 gold badges17 silver badges32 bronze badges 1
  • What you mean about "does not work"? Errors or something? – Ionică Bizău Commented Jun 23, 2013 at 6:47
Add a ment  | 

1 Answer 1

Reset to default 6

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

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论