<html>
<head>
<title></title>
<script>
//程序的作用是,先在页面上生成一个按键,这个按钮一按下去就再生成一个下拉框。function writeDiv(context,divId)
{
var div = document.getElementById(divId);
div.innerHTML = context;
}
function test()
{ tmp="<select name='select23' id='select23' onchange=\"selectChange('select23');\"><option value='1'>市场部<\/option><option value='2'>技术部<\/option><\/select> ";
var s="<INPUT TYPE=\"button\" value=\"Create\" onclick=\""+tmp+";\">";
writeDiv(tmp,"test");
} </script>
</head>
<body>
<div id="test">
<script>
test();
</script>
</body></html>
<head>
<title></title>
<script>
//程序的作用是,先在页面上生成一个按键,这个按钮一按下去就再生成一个下拉框。function writeDiv(context,divId)
{
var div = document.getElementById(divId);
div.innerHTML = context;
}
function test()
{ tmp="<select name='select23' id='select23' onchange=\"selectChange('select23');\"><option value='1'>市场部<\/option><option value='2'>技术部<\/option><\/select> ";
var s="<INPUT TYPE=\"button\" value=\"Create\" onclick=\""+tmp+";\">";
writeDiv(tmp,"test");
} </script>
</head>
<body>
<div id="test">
<script>
test();
</script>
</body></html>
这是什么意思?
<html>
<head>
<title></title>
<script>
//程序的作用是,先在页面上生成一个按键,这个按钮一按下去就再生成一个下拉框。 function writeDiv(context,divId)
{
var div = document.getElementById(divId);
div.innerHTML = context;
}
function test()
{
tmp="writeDiv(\"<select name='select23' id='select23' onchange='selectChange('select23');'><option value='1'>市场部<\/option><option value='2'>技术部<\/option><\/select>\",\"test\");";
var s="<INPUT TYPE=\"button\" value=\"Create\" onclick=\""+tmp+";\">";
writeDiv(s,"test");
} </script>
</head>
<body>
<div id="test">
<script>
test();
</script>
</body></html>
<head>
<title></title>
<script>
//程序的作用是,先在页面上生成一个按键,这个按钮一按下去就再生成一个下拉框。 function writeDiv(context,divId)
{
var div = document.getElementById(divId);
div.innerHTML = context;
}
function test()
{
var tmp="writeDiv('<select name=\\\'select23\\\' id=\\\'select23\\\' onchange=\\\'selectChange("select23");\\\'><option value=\\\'1\\\'>市场部<\/option><option value=\\\'2\\\'>技术部<\/option><\/select>','test');";
var s="<INPUT TYPE=\"button\" value=\"Create\" onclick=\""+tmp+";\">";
writeDiv(s,"test");
} </script>
</head>
<body>
<div id="test">
<script>
test();
</script>
<div onclick="alert( document.body.outerHTML )">test2</div>
</body></html>
<script>
function Load()
{
var the = document.createElement( "INPUT" ) ;
the.type = "button" ;
the.value = "Create" ;
the.onclick = function ()
{
var theSelect = document.createElement( "SELECT" ) ;
theSelect.name = "select23" ;
theSelect.id = "select23" ;
//theSelect.onchange = new Function( "selectChange( 'select23' )" ) ;
theSelect.onchange = new Function( "selectChange( this )" ) ;
var theOp ;
theOp = document.createElement("OPTION");
theOp.value = "1" ;
theOp.text = "市场部" ;
theSelect.add( theOp ) ;
theOp = document.createElement("OPTION");
theOp.value = "2" ;
theOp.text = "技术部" ;
theSelect.add( theOp ) ;
theSelect.selectedIndex = 0 ; writeDiv( theSelect, "theDiv" ) ;
} writeDiv( the, "theDiv" ) ;}
function writeDiv( the , theID )
{
var theObj = document.getElementById( theID );
if( theObj == null )
{
return ;
}
theObj.innerHTML = "" ;
theObj.appendChild( the ) ;
}
function selectChange( theSelect )
{
var str = "下拉框状态:\n" ;
str += "当前选中项的索引是 " + theSelect.selectedIndex + "\n" ;
str += "当前选中项的值是 " + theSelect.options[ theSelect.selectedIndex ].value + "\n" ;
str += "当前选中的文字是 " + theSelect.options[ theSelect.selectedIndex ].text + "\n" ;
alert( str )
}
</script>
<body onload="Load()">
<div id="theDiv"></div>
</body>
</html>