0

html で実際に変数を使用できないことはわかっていますが、これが可能かどうか疑問に思っています。私は周りを検索しましたが、私の質問に明確に答えるものは何も見つかりません。うまくいけば、誰かが私を正しい方向に向けることができます。これが私が考えていることです:

<!DOCTYPE html>
<html>
<body>

<input type="text" name="test">
<input type="submit" onclick="myFunction(test)">
<script type="text/javascript">
function myFunction(test)
{
alert("Welcome " + test);
}
</script>

</body>
</html>

これは機能しますか、それとも似たようなものですか?ありがとう、サム

4

2 に答える 2

3

入力の内容を変数として使用する場合:

<!DOCTYPE html>
<html>
<body>

<input type="text" id="some_id" name="test">
<input type="submit" onclick="myFunction(document.getElementById('some_id').value)">
<script type="text/javascript">
function myFunction(test)
{
alert("Welcome " + test);
}
</script>

</body>
</html>
于 2012-08-16T15:23:41.727 に答える
0

あなたの質問から私が理解したのは、あなたがアクセス<input>して送信してこれをfunction(test) 試してみたいということです:

<input type="text" name="test" id="test"> <-- Give ID here
<input type="submit" onclick="myFunction(test)"> <--Send same ID here
<script type="text/javascript">
function myFunction(test)
{
alert("Welcome " + test.value);
}
</script>

</body>
于 2012-08-16T15:24:27.677 に答える