2
以下のコードのonclick
は警告を正しく発しません。 Onclickは文字列を警告します
以下のコードのonclick
は警告を正しく発しません。 Onclickは文字列を警告します
function alert_phrase(id){
var value = document.getElementById(id).value;
alert(value);
}
<div id="exp" style="background-color: white;">
<p id="content-exp" style="color: red;">HELLO WORLD!</p>
<input name="phrase" Placheholder="Enter text here" id="phrase" />
<button onclick='alert_phrase(phrase)'>Alert this sentence</button>
</div>
<button onclick='alert_phrase("phrase")'>Alert this sentence</button>
注:文字列としてid
を渡すがalert_phraseする
は、ここに私のコードです。
スニペット:
function alert_phrase(id){
var value = document.getElementById(id).value;
alert(value);
}
<div id="exp" style="background-color: white;">
<p id="content-exp" style="color: red;">HELLO WORLD!</p>
<input name="phrase" Placheholder="Enter text here" id="phrase" />
<button onclick='alert_phrase("phrase")'>Alert this sentence</button>
</div>
あなたのパラメータに引用符を忘れています。これは
function alert_phrase(id){
var value = document.getElementById(id).value;
alert(value);
}
<div id="exp" style="background-color: white;">
<p id="content-exp" style="color: red;">HELLO WORLD!</p>
<input name="phrase" Placheholder="Enter text here" id="phrase" />
<button onclick='alert_phrase("phrase")'>Alert this sentence</button>
感謝を役に立てば幸い!それは私が助けることができてうれしい@ rforn – willy
うまくいった。私はこれらの自分を逃したときには、それが荒いと思っています。 – rfornal