次のコードに問題があります。文字列を別の文字列に置き換えて、imgコードを生成したい。しかし、エラーメッセージ「str.replace is not a function
」が表示されます。どんな考え?Javascript replace関数 "関数ではありません"
<input type="text" id="text">
<input type="button" value="See Code" onclick="myFunction();">
<input type="text" id="code" name="code">
<script>
function myFunction() {
var str = parseInt(document.getElementById("text").value);
var res = str.replace("ftpadress", "htmladress");
var code = str.concat("<img src='",res,"' width='100%'>");
document.getElementById("code").value = code;
}
</script>
でいいと思う
'str'それは' number'だ、 'parseInt'の結果である、そう。 ['.replace()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)はStringメソッドです。 – mrlew
[.replaceが関数ではないというエラーメッセージが表示されるのはなぜですか?](http://stackoverflow.com/questions/3141337/why-do-i-get-an-error-message-that- – Xufox
文字列 '' ftpadress ''を含む可能性のある値に対して' 'parseInt()'を呼び出すのはなぜですか? – nnnnnn