gpt4 book ai didi

javascript - 通过 JSON 接收数据后的可编辑文本框

转载 作者:行者123 更新时间:2023-11-29 10:22:13 25 4
gpt4 key购买 nike

我正在通过 JSON 从 state.jsp 接收数据,并在 auto.jsp 中的文本框中显示数据,该文本框的 ID 为 textbox2。但是我无法编辑接收数据的文本框,为什么?

//auto.jsp:

 $("#combo1").change(function() {
// by onchange event of combobox, i am displaying string "anyname"
// on that below textbox.
$.getJSON('state.jsp', { combo1Val : $(this).val() }, function(responsedata) {
$("#textbox2").replaceWith(responsedata.name);
});
});
// i am displaying "anyname" here, but why i am not able
// to edit this text box after displaying? I have not set it to readonly
<input type="text" id="textbox2" name="2ndtextbox/>

//状态.jsp

<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONArray"%>
<%
JSONObject arrayObj= new JSONObject();
arrayObj.put("name","anyname");// displaying "anyname" in that textbox
response.setContentType("application/json");
response.getWriter().write(arrayObj.toString());
%>

我在那个文本框中显示字符串“anyname”,但我不能再编辑这个文本框了,为什么?我没有将它设置为只读。任何帮助

最佳答案

.replaceWith()用指定的值(文本、dom 元素、jquery 对象)替换匹配的集合。因此,在您的代码中,您将 while INPUT 元素替换为您的响应数据,而不是设置其值

要设置表单元素的值,请使用 .val()方法:

$("#textbox2").val(responsedata.name);

关于javascript - 通过 JSON 接收数据后的可编辑文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9208610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com