从< head>传递var到< body> [英] passing var from <head> to <body>

查看:72
本文介绍了从< head>传递var到< body>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



< html>

< head>

< script>

function doIt( ){

var list = document.forms [0] .product;

var selItem = list.options [list.selectedIndex] .value;

^^^^^^^

< / head>

< body>

< script>

document.writeln(''< div id ="''+ selItem +''">''); // var不是

^^^^^ ^^^ //在这里阅读..

//如何将它从函数传递到这里?

< / script>

< / body>


这是动态内容..什么打印取决于什么项目用户

在sel obj中选择..谢谢..


<html>
<head>
<script>
function doIt() {
var list = document.forms[0].product;
var selItem = list.options[list.selectedIndex].value;
^^^^^^^
</head>
<body>
<script>
document.writeln(''<div id="'' + selItem + ''">'');// var not being
^^^^^^^^ // read here..
// how do I pass it from function to here?
</script>
</body>

this is for dynamic content.. what prints depens on what item user
selects in sel obj.. thank you..

推荐答案



" Frances" < FD *** @ yahoo.com>在消息中写道

news:43 ********************* @ news.sunsite.dk ...

"Frances" <fd***@yahoo.com> wrote in message
news:43*********************@news.sunsite.dk...

< html>
< head>
< script>
function doIt(){
var list = document.forms [0] .product ;
var selItem = list.options [list.selectedIndex] .value;
^^^^^^^
< / head>

< body> ;
< script>
document.writeln(''< div id ="''+ selItem +''">''); // var not
^^^^^^^^ //在这里阅读..
//如何将它从函数传递到这里?
< / script>
< / body>

这是针对动态内容..什么打印取决于用户在sel obj中选择什么项目..谢谢..

<html>
<head>
<script>
function doIt() {
var list = document.forms[0].product;
var selItem = list.options[list.selectedIndex].value;
^^^^^^^
</head>
<body>
<script>
document.writeln(''<div id="'' + selItem + ''">'');// var not being
^^^^^^^^ // read here..
// how do I pass it from function to here?
</script>
</body>

this is for dynamic content.. what prints depens on what item user selects
in sel obj.. thank you..




如果内容是动态的,你需要创建一个创建文本的函数和一个触发它的事件。例如你的

选择的onChange事件可以调用函数调用writeDynamicContent()然后吐出

< div>中的文本。



if the content is dynamic you will need to create a function that creates
the text and an event to trigger it. for example the onChange event of your
select could call a function call writeDynamicContent() which then spits out
the text in the <div>.


Zoe Brown写道:
Zoe Brown wrote:
" Frances" < FD *** @ yahoo.com>在消息中写道
新闻:43 ********************* @ news.sunsite.dk ...
"Frances" <fd***@yahoo.com> wrote in message
news:43*********************@news.sunsite.dk...
< html>
< head>
< script>
函数doIt(){
var list = document.forms [0] .product;
var selItem = list.options [list.selectedIndex] .value;
^^^^^^^
< / head>

< body>
< script>
document.writeln(''< div id ="''+ selItem +''">''); // var not not
^^^^ ^^^^ //在这里阅读..
//如何将它从函数传递到这里?
< / script>
< / body>

这是针对动态内容..什么打印取决于用户在sel obj中选择什么项目..谢谢..
<html>
<head>
<script>
function doIt() {
var list = document.forms[0].product;
var selItem = list.options[list.selectedIndex].value;
^^^^^^^
</head>
<body>
<script>
document.writeln(''<div id="'' + selItem + ''">'');// var not being
^^^^^^^^ // read here..
// how do I pass it from function to here?
</script>
</body>

this is for dynamic content.. what prints depens on what item user selects
in sel obj.. thank you..



如果内容是动态的,则需要创建一个创建文本的函数和一个触发它的事件。例如,你的
选择的onChange事件可以调用函数调用writeDynamicContent()然后吐出< div>中的文本。


if the content is dynamic you will need to create a function that creates
the text and an event to trigger it. for example the onChange event of your
select could call a function call writeDynamicContent() which then spits out
the text in the <div>.



是的,我正在调用doIt()(编写动态内容的函数)和/ b
onChange sel obj中的事件处理程序..但仍然内容不打印

我想把它变成b / c var是不是从函数传递到我想要打印内容的地方......你如何从

功能到外面吗?非常感谢你的帮助...


yes, I''m calling doIt() (function that writes dynamic content) with
onChange Event handler in sel obj.. but still content doesn''t print
where I want it to b/c var isn''t being passed from function to where I
want content to print... how DO you pass a variable from inside a
function to outside it? thank you very much for yr help...


Frances写道:
Frances wrote:

< html>
< head>
< script>
function doIt(){
var list = document.forms [0] .product;
var selItem = list.options [list.selectedIndex] .value;
^^^^^^^
< / head>

<html>
<head>
<script>
function doIt() {
var list = document.forms[0].product;
var selItem = list.options[list.selectedIndex].value;
^^^^^^^
</head>



list = document.forms [0] .product; //现在" list"是全球性的。


Mick


[snip]


list = document.forms[0].product; // Now "list" is global.

Mick

[snip]


这篇关于从&lt; head&gt;传递var到&lt; body&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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