<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 动态改变select值</title>
<script language="javascript">
var getselectvalue = funtion(select)
{
var idx = select.selectedindex,
option,
value;
if (idx > -1) {
option = select.options[idx];
value = option.attributes.value;
return (value && value.specified) ? option.value : option.text);
}
return null;
}
</script>
</head>
<body>
<script type="text/javascript">
var getselectvalue = function(select) {
var idx = select.selectedindex,
option,
value;
if (idx > -1) {
option = select.options[idx];
value = option.attributes.value;
return (value && value.specified) ? option.value : option.text;
}
return null;
}
</script>
<select id="111cnnet" onchange="alert(getselectvalue(document.getelementbyid('111cnnet')))">
<option value="http://www.111cn.net">网页制作教程</option>
<option value="http://mb.111cn.net">模板</option>
</select>
</body>
</html>
其它关于网页特效 select内容,
1.判断select选项中 是否存在value="paravalue"的item
function 网页特效selectisexititem(objselect, objitemvalue) {
var isexit = false;
for (var i = 0; i < objselect.options.length; i++) {
if (objselect.options[i].value == objitemvalue) {
isexit = true;
break;
}
}
return isexit;
}
// 2.向select选项中 加入一个item
function jsadditemtoselect(objselect, objitemtext, objitemvalue) {
//判断是否存在
if (jsselectisexititem(objselect, objitemvalue)) {
alert("该item的value值已经存在");
} else {
var varitem = new option(objitemtext, objitemvalue);
objselect.options.add(varitem);
alert("成功加入");
}
}
// 3.从select选项中 删除一个item
function jsremoveitemfromselect(objselect, objitemvalue) {
//判断是否存在
if (jsselectisexititem(objselect, objitemvalue)) {
for (var i = 0; i < objselect.options.length; i++) {
if (objselect.options[i].value == objitemvalue) {
objselect.options.remove(i);
break;
}
}
alert("成功删除");
} else {
alert("该select中 不存在该项");
}
}
// 4.删除select中选中的项
function jsremoveselecteditemfromselect(objselect) {
var length = objselect.options.length - 1;
for(var i = length; i >= 0; i--){
if(objselect[i].selected == true){
objselect.options[i] = null;
}
}
}