如何使用jquery / javascript替换字符串中的字符? [英] How to replace characters from a string using jquery/javascript?
本文介绍了如何使用jquery / javascript替换字符串中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数组元素为1 * 2 *。然后我想从1 * 2 *替换2 *并得到1 *
如何在jquery / javascript中执行此操作?
谢谢..
Hi,
i have an array element as 1*2* . then i want to replace 2* from 1*2* and get result as 1*
how to do it in jquery/javascript?
THanks..
推荐答案
你好,
下面是一个简短的片段,向您展示如何在JavaScript中执行此操作。
Hello,
Below is a short snippet which shows you how to do this in JavaScript.
<html>
<body>
<p>Click the button to remove "2*" in the paragraph below:</p>
<p id="demo">1*2*</p>
<button onclick="myFunction()">Try it</button>
<script type="text/Javascript">
function myFunction() {
var str=document.getElementById("demo").innerHTML;
var n = str.replace(/\d\*
/, );
document .getElementById( demo).innerHTML=n;
}
< / 脚本 >
< / body >
< / html >
/,""); document.getElementById("demo").innerHTML=n; } </script> </body> </html>
问候,
Regards,
这篇关于如何使用jquery / javascript替换字符串中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文