当我用 javascript 填充文本字段时,文本字段值为空
我正在使用 modalpopup 在文本字段中输入一些值。在modalpopup视图中选择值后,modalpopup关闭,值取合适的值。即使值显示在文本字段中,textfield1.text
也会返回空字符串。当我看到源代码(html)时,我发现即使文本字段也没有显示任何内容;它还没有真正输入这个值,因为相应的 html 输入字段还没有得到值。
这是我用来填充此文本字段的代码:
function CloseRequestModal(s)
{
document.getElementById('<%=txtRequest.ClientID%>').value = s;
var mpu = $find('<%=ModalPopupExtender3.ClientID%>');
mpu.hide();
}
请帮忙。
I am using modalpopup to enter some value in a textfield. After the value is selected in the modalpopup view, the modalpopup is closed and the value takes the appropriate value. Even if the value is displayed in the textfield, the textfield1.text
returns an empty string. When I see the source code (html), I see that even the textfield isn't displaying anything; it hasn't really had this value input, because the appropriate html input field hasn't got a value yet.
This is the code I use to fill this textfield:
function CloseRequestModal(s)
{
document.getElementById('<%=txtRequest.ClientID%>').value = s;
var mpu = $find('<%=ModalPopupExtender3.ClientID%>');
mpu.hide();
}
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我需要查看源 HTML,因为看起来您已将模板语言混合到您的 javascript 中,但也许您使用“textfield1.value”而不是“textfield1.text”?
此外,您需要查看“生成的”源代码(使用浏览器插件)或使用 safari/chrome 上的 Web 检查器或 Firefox 上的 firebug 检查节点,以便查看您使用 javascript 所做的更改。
I would need to see source HTML cause it looks like you have template language mixed into your javascript but perhaps instead of "textfield1.text" you use "textfield1.value"?
Additionally, you would need to view "generated" source (with a browser plugin) or inspect the node with web inspector on safari/chrome or firebug on firefox in order to see the change that you made with javascript.
我用另一种方式解决了这个问题。
即使该值存在(在文本字段中),也不会触发任何事件,以让浏览器/编译器知道该值确实存在。
所以我决定,尽管编辑了文本字段的值,我也将该值存储在会话中。在这种情况下,该值会在界面中显示给用户所需的值,另一方面,我使用存储在会话中的值。
i fixed this problem in an alternate way.
even if the value is there (in the textfield), none of the events is fired, to let know the browser / compilator that the value really exists.
so i decided, despite editing the value of the textfield, i store this value in the session too. in this case, the value is displayed for user needed in the interface, and on the other hand i use the value that i stored in the session.