document link https://developers.weixin.qq.
there is a bindReplaceInput method in the sample code as follows. The purpose of this code is: if I enter two digits in a row, 1meme 11 will become 2
.bindReplaceInput: function (e) {
var value = e.detail.value
var pos = e.detail.cursor
var left
if (pos !== -1) {
//
left = e.detail.value.slice(0, pos);
//
pos = left.replace(/11/g, "2").length;
}
//
return {
value: value.replace(/11/g, "2"),
cursor: pos
}
}
my question is:
-
In the
- code, there is an if (pos! = =-1). May I ask why the value of pos is compared to-1? It seems that the value of pos will not be equal to a negative number
- in the sentence segment of if, if the value of left does not contain 11, left.replace (/ 11 li) cannot replace 11 with 2 because 11 cannot be found, so why does this statement not report an error
novice, please give me a lot of advice and thanks!