您现在的位置是:首页 > 电脑技术查询 > web开发

请问replace的有关问题,请赐教

编辑:chaxungu时间:2022-10-02 23:20:29分类:web开发

请教replace的问题,请赐教
textB.value.replace(textD.value,textA.value)是可以执行的
但是如果改成textB.value.replace(textD.value/g,textA.value)却报错,请教如何实现/g的匹配全部的效果。
完整代码如下:
<input name= "textA " type= "text " value= "看 " width= "100px ">
里的内容,替换
<input name= "textB " type= "text " value= "fdsafasfgfdgfsd ">
</label>
里的
<input name= "textD " type= "text " value= "d " width= "100px ">
<input type= "button " name= "Submit " value= "开始替换 "
onClick= "var beReplace=/textD.value/g;
textB.value=textB.value.replace(textD.value,textA.value) ">

请高手赐教


------解决方案--------------------
replace的第一个参数是字符串或者正则表达式
第二个参数是字符串或者函数引用

xx.value/g不能被识别的
可以用new RegExp(xx.value, "g ")来创建正则