简体   繁体   English

在 javascript / jquery 中显示未定义的输入类型文本值

[英]input type text value showing undefined in javascript / jquery

I have one input type textbox, passing value from that textbox to the controller in .net mvc via javascript.我有一个输入类型文本框,通过 javascript 将该文本框中的值传递给 .net mvc 中的 controller。 Now, my problem is that in textbox I put the value but in javascript/jquery alert it showing me undefined.现在,我的问题是我在文本框中输入了值,但在 javascript/jquery 警报中显示我未定义。

Here is my code,这是我的代码,

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="text" placeholder="SVG00001" name="referencecode" id="referencecode" /> <button class="Referencebutton" onclick="AddReferenceCode()"><span>Submit</span></button> <script> function AddReferenceCode() { alert($('#referencecode').val()); } </script>

I used javascript as well as jquery type also to get the value from input text.我还使用 javascript 和 jquery 类型从输入文本中获取值。 But nothing work.但没有任何工作。

As per the code seen, I dont think so is there any problem in code still shows the undefined value.根据看到的代码,我认为代码中是否有任何问题仍然显示未定义的值。 Surprised...!!!惊讶……!!!

Are they wrapped in a form with a valid input tag which has the attribute type="submit ?它们是否包含在具有属性type="submit的有效输入标签的表单中?

first try adding value="" to the首先尝试将 value="" 添加到

if that does not work try using the.html() in your jquery如果这不起作用,请尝试在 jquery 中使用 the.html()

let me know how you get on.让我知道你是怎么办的。

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

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