问题描述
< 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..
推荐答案
如果内容是动态的,你需要创建一个创建文本的函数和一个触发它的事件。例如你的
选择的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>.
如果内容是动态的,则需要创建一个创建文本的函数和一个触发它的事件。例如,你的
选择的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...
list = document.forms [0] .product; //现在" list"是全球性的。
Mick
[snip]
list = document.forms[0].product; // Now "list" is global.
Mick
[snip]
这篇关于从< head>传递var到< body>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!