当附加到div时,我得到输入框值为undefined.下面是代码.
JS:
$('#submitHook').click(function () {
var v = ('#try').val();
alert(v);
$('#container').prepend('<tr><td>' + v + '</td></tr>');
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<code>
<input type="text" id="try"></input>
<input type="button" id="submitHook"></input>
<table id="container></table>
</code>
Run Code Online (Sandbox Code Playgroud)
同样如何将其扩展到textarea?感谢任何帮助.
你之前错过了$('#try')
$('#submitHook').click(function(){
var v = $('#try').val();
alert(v);
$('#container').prepend(''+v+'');
});
Run Code Online (Sandbox Code Playgroud)