為什么 document.write(mystr.indexOf("o",6)); 和 document.write(mystr.indexOf("o",7));的輸出值都為7,到底哪個是正確的?
<title>string對象?</title>
<script?type="text/javascript">
??var?mystr="Hello?World!"
??document.write(mystr.indexOf("o",7));
</script><title>string對象?</title>
<script?type="text/javascript">
??var?mystr="Hello?World!"
??document.write(mystr.indexOf("o",7));
</script>2016-11-28
舉報
2016-11-30
都是對的,沒問題啊。mystr.indexOf("o",6) 6代表開始檢索位,不是只檢索第6個字符。
2016-11-29
那是對的,startpos是指從0到length-1這些中間開始檢索的
2016-11-29
都是對的,你是:從第6個或者第7個位置起,檢索“o”的位置。第二個“o”的下標為7??崭褚舱嘉?/p>
2016-11-28
mystr 調用了indexof方法