2017-07-07 1 views
0

入力に入力されたものがあれば何でも既存のテキストを変更しようとしています。私はid = "text"から取り出そうとしますが、それはうまくいかず、単にテキストを表示します。入力IDからテキストを変更する

<input type="text" class="form-control" id="text" placeholder="Type your text here....."> 

<div class="form-group"> 
    <button>submit</button> 
</div> 
<div class="form-group" id="response"> 
    <pre>Type some text in the above text field, then log the text out here on button click</pre> 
</div> 


<script> 
    $('button').click(function() { 
     $("#response").text("#text"); 
    }); 
</script> 
+0

'$( "#応答")。テキスト($("#から値を取得しますテキスト ")。val());' – Satpal

答えて

0

今のところ文字列#textが渡されているため、表示されます。 .val()を使用してinputの値を取得してから設定してください。

$("#response").text($("#text").val()); 
1

$('button').click(function() { 
 
    
 
    $("#response").text($("#text").val()); 
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<input type="text" class="form-control" id="text" placeholder="Type your text here.....">   
 

 
    <div class="form-group"> 
 
    <button>submit</button> 
 
    </div> 
 
    <div class="form-group" id="response"> 
 
    <pre>Type some text in the above text field, then log the text out here on button click</pre> 
 
    </div> 
 

 

 

 
<script> 
 
    
 
</script>

1

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="text" class="form-control" id="text" placeholder="Type your text here.....">   
 

 
    <div class="form-group"> 
 
    <button>submit</button> 
 
    </div> 
 
    <div class="form-group" id="response"> 
 
    <pre>Type some text in the above text field, then log the text out here on button click</pre> 
 
    </div> 
 

 

 

 
<script> 
 
    $('button').click(function() { 
 
    $("#response").text($("#text").val()); 
 
}); 
 
</script>

使用$("#text").val()は、入力

関連する問題