简体   繁体   English

输入字段不会获得更新的值

[英]Input field wouldn't get the updated value

I have an input field with id Email and im getting the value of this field to update my object. 我有一个ID为Email的输入字段,即时消息获取此字段的值来更新我的对象。 However when i try to edit it again without a refresh and try to send it via Ajax, email field becomes empty. 但是,当我尝试再次编辑而不进行刷新并尝试通过Ajax发送它时,电子邮件字段将变为空。 I get this field by using $("#Email").val() and I tried using .attr("value") as well however this gets the old value of the field not the new value. 我通过使用$(“#Email”)。val()来获取该字段,并且尝试使用.attr(“ value”)来获取该字段,但是这会获取该字段的旧值而不是新值。

My problem is similar to this " jQuery showing empty string on input text? " however, I can't use the solution there as I have to use the input box multiple times after updating. 我的问题类似于此“ jQuery在输入文本上显示空字符串吗? ”,但是,由于在更新后必须多次使用输入框,因此无法在其中使用解决方案。

However when i try to edit it again without a refresh and try to send it via Ajax, email field becomes empty. 但是,当我尝试再次编辑而不进行刷新并尝试通过Ajax发送它时,电子邮件字段将变为空。

Are you sure the page is not refreshing? 您确定页面没有刷新吗? The field can only become empty from either a refresh, or actual JavaScript code you have written/included that is causing the problem. 刷新或导致问题的已编写/包含的实际JavaScript代码只能使该字段为空。

$("#Email").val() will read the value and will not blank it out. $("#Email").val()将读取该值,并且不会将其清空。

.attr("value") will read what the value was when the page loaded, but not accounting for changes made by the user. .attr("value")将读取页面加载时的值,但不考虑用户所做的更改。

My problem is similar to this " jQuery showing empty string on input text? " however, I can't use the solution there as I have to use the input box multiple times after updating. 我的问题类似于此“ jQuery在输入文本上显示空字符串吗? ”,但是,由于在更新后必须多次使用输入框,因此无法在其中使用解决方案。

Do you understand the reason for that solution? 您了解该解决方案的原因吗? The problem there was that the value was captured to a variable Name too early. 那里的问题是该值太早被捕获到变量Name The solution was to move the call to val() to later. 解决方案是将对val()的调用移到以后。 (after blur took effect, not before) blur生效后,而不是之前)


I hope these are helpful, but there's really not much more I could tell you without seeing your code. 希望这些对您有所帮助,但是在看不到您的代码的情况下,我能告诉您的内容实际上没有太多。

I expect this question to be closed due to lack of details. 由于缺乏细节,我希望这个问题能够解决。 When you post the new question, please try to fix one problem at a time (either "becomes empty", or "gets old value") and post enough details for a solution. 发布新问题时,请尝试一次解决一个问题(“变空”或“获取旧价值”)并发布足够的详细信息以寻求解决方案。 (ie an SSCCE) (即SSCCE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM