使用document.write输出INPUT文本字段的VALUE [英] Output VALUE of INPUT textfield using document.write

查看:103
本文介绍了使用document.write输出INPUT文本字段的VALUE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我真的,真的,需要一些帮助 - 我花了好几个小时试图找到一个

解决方案。


简而言之,我正在尝试让用户输入表格'

文本字段中的值。然后应该使用document.write将值赋值给变量并输出




(注意,没有提交按钮或其他表单元素。基本上

无论用户在INPUT文本字段中放置什么,我都希望在网页上回显

。)


---


这里有希望发生的事情:


[myName](网页访问者在输入文字字段中输入值)


欢迎myName! (文本字段的值出现在网页上使用

document.write。


---


什么我到目前为止:


我知道我可以声明一个值并使用document.write。


var myName =" Tom" ;;


document.write =(myName);


但是如何将INPUT文本字段的VALUE分配给变量名

并使用document.write输出?请帮忙 - 我花了好几个小时

这个!


提前致谢

难倒和困惑。


-

使用Opera革命性的电子邮件客户端: http://www.opera.com/m2/

Hello,

I really, really, need some help here - I''ve spent hours trying to find a
solution.

In a nutshell, I''m trying to have a user input a value in form''s
textfield. The value should then be assigned to a variable and output
using document.write.

(Note, there is no submit button or other form elements. Basically
whatever the user places in the INPUT textfield, I want echoed elsewhere
on the webpage.)

---

Here''s what hopefully should happen:

[ myName ] (web visitor types value in Input Text Field)

Welcome myName! (value of text field appears in web page using
document.write.

---

What I have so far:

I know I can declare a value and use document.write.

var myName = "Tom";

document.write=(myName);

But how do I assign the VALUE of the INPUT textfield to a variable name
and have it output using document.write? Please help - I''ve spent hours on
this!

Thanks in advance.
Stumped & Confused.

--
Using Opera''s revolutionary e-mail client: http://www.opera.com/m2/

推荐答案

Stumped and Confused写道:
Stumped and Confused wrote:
简而言之,我正在尝试让用户输入表格中的值
textfield。然后应该将值赋给vari能够和输出
使用document.write。
In a nutshell, I''m trying to have a user input a value in form''s
textfield. The value should then be assigned to a variable and output
using document.write.



document.write将打开一个新文档,清除当前文档,

这可能不是你想要的。常见问题解答中的dynWrite函数

应该会给你更好的结果:-)


< URL:http://jibbering.com/faq/#FAQ4_15> ;


但是如果你只想写文本而不是HTML,那么使用标准DOM方法可能会更好。

< form action ="#">

你叫什么名字& nbsp;?

< input>

< input type =" button" value =": - )"

onclick =" hello(this.form.elements [0] .value,''foo'')">

< / form>

< span id =" foo">< / span>


< script type =" text / javascript">

函数hello(what,where){

var target;

if(document.getElementById&&

document.createTextNode&&

document.body&&

document.body.appendChild&&

typeof document.body.firstChild!=" undefined"

){//支持我们想要使用的所有方法


target = document.getElementById(where);

if(target){

if(target.firstChild == null){

//第一次调用

//添加文本节点

target.appendChild(document.createTextNode(""));

}

if(/\S/.test(what)){// not empty

target.firstChild.nodeValue =" Hello," +什么;

}

}


}

}

< / script>



document.write will open a new document, clearing the current document,
which is probably not what you want. The dynWrite function from the FAQ
should give you better results:-)

<URL:http://jibbering.com/faq/#FAQ4_15>

However if you just want to write text and not HTML, it''s probably
better to use standard DOM methods.
<form action="#">
What''s you name&nbsp;?
<input>
<input type="button" value=":-)"
onclick="hello(this.form.elements[0].value,''foo'')">
</form>
<span id="foo"></span>

<script type="text/javascript">
function hello(what,where){
var target;
if(document.getElementById &&
document.createTextNode &&
document.body &&
document.body.appendChild &&
typeof document.body.firstChild!="undefined"
){ //all the methods we want to use are supported

target=document.getElementById(where);
if(target) {
if(target.firstChild==null) {
//first time calling
//add the text node
target.appendChild(document.createTextNode(""));
}
if(/\S/.test(what)) { //not empty
target.firstChild.nodeValue="Hello, "+what;
}
}

}
}
</script>


" Stumped and Confused" <无**** @ jollydonkey.com>写在消息

新闻:opsehi7fmi0q60t7 @ shaktiman
"Stumped and Confused" <no****@jollydonkey.com> wrote in message
news:opsehi7fmi0q60t7@shaktiman
你好,

我真的,真的,需要一些帮助 - 我花了几个小时试图找到一个解决方案。

简而言之,我正在尝试让用户输入表格'
文本字段中的值。然后应该使用document.write将值分配给变量和输出。
Hello,

I really, really, need some help here - I''ve spent hours trying to
find a solution.

In a nutshell, I''m trying to have a user input a value in form''s
textfield. The value should then be assigned to a variable and output
using document.write.




我有一个转换脚本,可能会强制执行您想要的操作。

必须等到星期一,因为它正在PC上工作。


它一定是垃圾,因为它是一个第一个可用的脚本我写了但是如果你没有在星期一找到解决方案,我会在这里发布相关的

位。



I had a conversion script which may be coerced into doing what you want.
Have to wait until Monday though because it''s on the PC at work.

It''s bound to be crap because it was one of the first useable scripts I
wrote but if you''ve not found a solution by Monday I''ll post the relevant
bits here.


非常感谢!


-

使用Opera的革命性电子邮件客户端: http://www.opera.com/m2/
Thanks a bunch!

--
Using Opera''s revolutionary e-mail client: http://www.opera.com/m2/


这篇关于使用document.write输出INPUT文本字段的VALUE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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