这里我是jquery的新手请帮助我如何将文本框值分配给另一个tex喜欢
<b>Enter Some Text</b> <input type="text" id="TxtHelp" /><br />
<button id="HelloModal" class="btn">ModalPop</button>
当我在文本框中输入文字时单击Span显示值的按钮,但为什么texbox不显示
<span id="Span1"></span><br />
<input type="text" class="form-control" id="JanMic" /><b>hhh</b>
Jquery的
$('#HelloModal').click(function () {
var txt = $('#TxtHelp').val();
$('#Span1').append(txt); //Its showing
$('#JanMic').append(txt); //Its not showing
})
答案 0 :(得分:2)
将append()
更改为val()以更改输入值:
$('#HelloModal').click(function () {
var txt = $('#TxtHelp').val();
$('#Span1').append(txt);
$('#JanMic').val(txt);
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<b>Enter Some Text</b> <input type="text" id="TxtHelp" /><br />
<button id="HelloModal" class="btn">ModalPop</button>
<span id="Span1"></span><br />
<input type="text" class="form-control" id="JanMic"><b>hhh</b>