2016-06-26 57 views
1

私がしようとしているのは、テキスト入力のval()を取得することだけです。ここにはexampleがあります。JQueryが要素の入力値を取得できません

私は外部リンクが許可されている場合ので、私もそれをここに貼り付けられます知らない:私は、この要素の値を取得できない理由

<div class="input-group"> 
    <input type="text" id="#test" class="form-control" aria-label="..." style='border-radius:4px;'> 
</div> 

<script> 
    // Always shows up as undefined..not "". 
    console.log($("#test").val()); 
</script> 

誰でも知っていますか?このことができます

<input type="text" id="#test" class="form-control" aria-label="..." .. 
//_____________________^ 

希望を:

答えて

2

あなたがid属性から#記号を削除する必要があります。


<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<script src="https://code.jquery.com/jquery-3.0.0.js"></script> 
 
<script src="https://code.jquery.com/jquery.min.js"></script> 
 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>Why can't I get the input value of the #test?</title> 
 
</head> 
 
<body style='padding:64px;'> 
 

 
    <div class="input-group"> 
 
    <input type="text" value="test value" id="test" class="form-control" aria-label="..." style='border-radius:4px;'> 
 
    </div> 
 
    
 
    <script> 
 
    // Always shows up as undefined..not "". 
 
    console.log($("#test").val()); 
 
    </script> 
 
    
 
</body> 
 
</html>

+0

あ.. :(これはあなたが長すぎるまで滞在するときに起こることです。おかげで、しかし、しばらくそこのために、私は下に影要素とは何かだと思いました入力。 – ThatGuy343

関連する問題