我正在尝试将下面代码中#response 的值显示到输入字段中。我不确定该怎么做。如果我使用
<div id="response"></div>
这将显示结果,但我喜欢将其显示在输入字段中。 我试过了,
<input type="text" id="response"/>.
这个没有显示结果 知道如何做到这一点。提前致谢。
<script>
$(document).ready(function() {
$("#productID").change(function() {
//alert($('#productID option:selected').val());
var pId = $('#productID').val();
$.get('updateProduct', {
productID: pId.trim() //using trim to get rid of any extra invisible character from pId
},
function(responseText) {
$('#response').text(responseText);
});
});
});
</script>
$('#response').val(responseText); --> 如果这包含两个值,那么有没有办法分别检索这些值?我想做的是将值分别显示到两个单独的输入字段中。
$('#response').val(responseText);
这可能包含产品描述、产品评论、产品类型等值。 这些值来自 servlet。 收到这些值后,它们将显示在三个单独的输入字段中。
此刻,如果我执行以下操作,
<input type="text" id="response"/>
这将在同一个输入字段中显示所有三个值。
最佳答案
input
元素值使用 jQuery's val()
method 设置,而不是 text()
。
改变:
$('#response').text(responseText);
收件人:
$('#response').val(responseText);
关于jquery - 在输入字段中显示 JQuery 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25422145/