简体   繁体   English

令人困惑的Javascript问题验证表单。 输入字段值有效,但不保存输入字段的对象

[英]Confusing Javascript issue validating form. Input field value works, but saving object of input field doesn't

Apologies for the unweildy title, this is a very difficult question to put into words. 不好意思的标题,这是一个很难说的问题。 This code will explain it much better. 这段代码将更好地解释它。

alert(formob.Nam.value); //i work correctly
alert(formob.Num.value); //and me  

name=formob.Nam; 
console.log(name); //[object HTMLInputElement]
console.log("name set "+name.value); //i return 'name set undefined'

num=formob.Num;
console.log(num); //<input type="text" name="Num">
console.log("num set "+num.value); //i return 'num set [value entered]' correctly

Simplified HTML: 简化的HTML:

<form method="post" class="well" name="FooterCall">
<input type="text" name="Nam">
<input type="text" name="Num">
<button... onmousedown="subajax(this.form...)"..>

Summary: Two essentially identical fields are being set in a form, but one sets incorrectly when the field is set to a Javascript object. 简介:一个表单中设置了两个基本相同的字段,但是当该字段设置为Javascript对象时,一个字段设置不正确。

Thankyou very much in advance for any help that can be offered! 非常感谢您提供的任何帮助! :) :)

if you use the following HTML 如果您使用以下HTML

<form method="post" name="formob">
<input type="text" name="Nam">
<input type="text" name="Num">
</form>
​

and check this JavaScript where you do not use name as variable name it should work imho. 并在不使用name作为变量名的地方检查此JavaScript,它应该可以正常运行。 formob needs to be a reference to the form of course: formob需要参考以下形式:

console.log(formob.Nam.value); //i work correctly
console.log(formob.Num.value); //and me  

xname = formob.Nam;
console.log(xname); //[object HTMLInputElement]
console.log("name set " + xname.value); //i return 'name set undefined'

num = formob.Num;
console.log(num); //<input type="text" name="Num">
console.log("num set " + num.value); //i return 'num set [value entered]' correctly​

this should work 这应该工作

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

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