var str="Hello World!";
var patt=/\x57/g;
var matched = str.match(patt);
document.write(matched.strike());
看来问题出在matched.strike()
。只有 matched
才有效。那为什么?
最佳答案
.strike()
方法对字符串进行操作,matched
是一个数组。您必须取消引用第一个匹配项才能看到正确的输出。
var str="Hello World!";
var patt=/\x57/g;
var matched = str.match(patt);
// Access first element of the matched array
document.write(matched[0].strike());
// Or via .pop() or .shift()
document.write(matched.pop().strike());
// or
document.write(matched.shift().strike());
// either returns "<strike>W</strike>"
String.strike()
method is nonstandard , 不应依赖于完整的浏览器支持。
关于javascript - 为什么这不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13290708/