无法获得html表单字段的值 [英] Can't get value into html form field

查看:75
本文介绍了无法获得html表单字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



谁能告诉我这里我做错了什么?


============== ====================


< html>

< head>

< title>测试表格< / title>

< script language =" JavaScript" type =" text / javascript">

< / head>


< body>


< script type =" text / javascript">

document.EmailFound.CMName.value =" Fanny";

< / script>


< form method =" POST"名称= QUOT; EmailFound" id =" EmailFound">

< input name =" CMName" />

< input type =" submit"值= [提交"命名= [提交" />

< / form>


< / body>


< / html>


==================================


" Fanny"将不会出现在输入字段中。


Can anyone tell me what I''m doing wrong here?

==================================

<html>
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">
</head>

<body>

<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>

<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />
<input type="submit" value="Submit" name="submit" />
</form>

</body>

</html>

==================================

"Fanny" will not appear in the input field.

推荐答案

Kelly写道:
Kelly wrote:

任何人都可以告诉我这里我做错了什么?


=========================== =======

< html>
Can anyone tell me what I''m doing wrong here?

==================================

<html>



缺少doctype声明。
http://www.htmlhelp.com/tools/validator/doctype.html


< head>

< title>测试表格< / title>

< script language =" JavaScript"类型= QUOT;文本/ JavaScript的">
<head>
<title>Test Form</title>
<script language="JavaScript" type="text/javascript">



< scripttag未关闭。

<scripttag not closed.


< / head>

< body>


< script type =" text / javascript">

document.EmailFound.CMName.value = Fanny;

< / script>
</head>

<body>

<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>



document.EmailFound.CMName目前还不是

代码执行的对象。基本流程仍然是自上而下的。


为了更好的向后兼容性,还可以使用:


document.forms ['' EmailFound'']。elements [''CMName'']。值


代替


document.EmailFound.CMName.value

document.EmailFound.CMName is not an object yet at this point of the
code execution. The basic flow is still top-down.

For a better backwards compatibility, one could also use:

document.forms[''EmailFound''].elements[''CMName''].value

in stead of

document.EmailFound.CMName.value


< form method =" POST"名称= QUOT; EmailFound" id =" EmailFound">

< input name =" CMName" />
<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />



虽然不是严格要求,但这应该是< input type =" text"

name =" CMName">。

Though not strictly required, this should be <input type="text"
name="CMName">.


< input type =" submit"值= [提交"命名= [提交" />

< / form>

< / body>

< / html>
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>



所有在一起:


<!doctype HTML public" - // W3C // DTD HTML 4.01 // EN"

" http://www.w3.org/TR/html4/strict.dtd">

< html>

< head>

< title>测试表格< / title>

< / head>

< body

onLoad =" document.EmailFound.CMName.value =''Fanny'';" >

< form method =" POST" name =" EmailFound">

< input type =" text" name =" CMName">

< input type =" submit" value =" Submit">

< / form>

< / body>

< / html>


''onLoad''事件处理程序在页面完全加载完毕后执行。


希望这有助于,


-

巴特

All together:

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form</title>
</head>
<body
onLoad="document.EmailFound.CMName.value=''Fanny'';" >
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>
</body>
</html>

The ''onLoad'' event handler is executed right after the page has fully
loaded.

Hope this helps,

--
Bart


7月18日,4:45 * pm,凯利< jor ... @ pobox.comwrote:
On Jul 18, 4:45*pm, Kelly <jor...@pobox.comwrote:

谁能告诉我这里我做错了什么?


范妮不会出现在输入字段中。
Can anyone tell me what I''m doing wrong here?

"Fanny" will not appear in the input field.



< html>

< head>

< title>测试表< / title>

< / head>

< body>

< form method =" POST"名称= QUOT; EmailFound" id =" EmailFound">

< input name =" CMName" />

< input type =" submit"值= [提交"命名= [提交" />

< / form>

< script type =" text / javascript">

document.EmailFound.CMName .value =" Fanny";

< / script>

< / body>

< / html>


--Jorge

<html>
<head>
<title>Test Form</title>
</head>
<body>
<form method="POST" name="EmailFound" id="EmailFound">
<input name="CMName" />
<input type="submit" value="Submit" name="submit" />
</form>
<script type="text/javascript">
document.EmailFound.CMName.value="Fanny";
</script>
</body>
</html>

--Jorge


7月18日,11:12 * am,Jorge< jo ... @ jorgechamorro.comwrote:
On Jul 18, 11:12*am, Jorge <jo...@jorgechamorro.comwrote:

7月18日,4:45 * pm,Kelly< jor ... @ pobox.comwrote:
On Jul 18, 4:45*pm, Kelly <jor...@pobox.comwrote:

谁能告诉我这里我做错了什么?
Can anyone tell me what I''m doing wrong here?


" Fanny"不会出现在输入字段中。
"Fanny" will not appear in the input field.



< html>

< head>

*< title>测试表< / title> ;

< / head>

< body>

*< form method =" POST"名称= QUOT; EmailFound" id =" EmailFound">

* *< input name =" CMName" />

* *< input type =" submit"值= [提交"命名= [提交" />

*< / form>

*< script type =" text / javascript">

* document。 EmailFound.CMName.value =" Fanny";

*< / script>

< / body>

< / html> ;


--Jorge


<html>
<head>
*<title>Test Form</title>
</head>
<body>
*<form method="POST" name="EmailFound" id="EmailFound">
* *<input name="CMName" />
* *<input type="submit" value="Submit" name="submit" />
*</form>
*<script type="text/javascript">
*document.EmailFound.CMName.value="Fanny";
*</script>
</body>
</html>

--Jorge



谢谢你们两位,它很棒!


但是现在我想放回一些我为了

而剥离的代码示例,我再也无法让它工作了。


我不想要范妮要硬编码,但要从

函数调用返回。这是经过调整的代码,带有精简的

功能:


================== ===============================

<!doctype HTML public" ; - // W3C // DTD HTML 4.01 // EN"

" http://www.w3.org/TR/html4/strict.dtd">

< html>

< head>

< title>测试表格< / title>

< / head>


< script type =" text / javascript">

function getValue();

return" Fanny" ;

< / script>


< body

< form method =" POST" name =" EmailFound">

< input type =" text" name =" CMName">

< input type =" submit" value =" Submit">

< / form>


< script type =" text / javascript">

document.EmailFound.CMName.value = getvalue();

< / script>


< / body>

< / html>


============================= ====================

Thank you both, it works great!

But now that I want to put back some of the code I stripped out for
the example, I can''t get it to work again.

I don''t want "Fanny" to be hardcoded, but to be returned from a
function call. Here is the adjusted code with a stripped-down
function:

=================================================

<!doctype HTML public "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form</title>
</head>

<script type="text/javascript">
function getValue();
return "Fanny";
</script>

<body
<form method="POST" name="EmailFound">
<input type="text" name="CMName">
<input type="submit" value="Submit">
</form>

<script type="text/javascript">
document.EmailFound.CMName.value=getvalue();
</script>

</body>
</html>

=================================================


这篇关于无法获得html表单字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆