您现在的位置是:首页 > 学无止境> JS网站首页学无止境JS

预选选择后自动填入文本框

简介预选选择后自动填入文本框

<!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>预选选择后自动填入文本框</title>
<style>
*{ margin:0; padding:0;}
li{ list-style:none;}
#yuxuan{ width:200px; height:auto; border:2px solid #C33; padding:5px;}
#yuxuan li{ line-height:30px; border-bottom:1px dashed #333; cursor:pointer;}
</style>
</head>

<body>
<script type=”text/javascript” src=”js/jquery.js”></script>
<script type=”text/javascript”>
$(document).ready(function(e) {
$(“#yuxuan li”).each(function(index, element) {
$(this).click(function(){
$i=$(this).index();
//alert($(“#yuxuan li”).eq($i).text());
$val=$(“#yuxuan li”).eq($i).text();
$(“#contents”).text($val);
});
//alert(index);
});
//$(“#contents”).text(“111″);
});
</script>
<textarea name=”” name=”content” id=”contents”></textarea>
<ul id=”yuxuan”>
<li>1111111</li>
<li>2222222</li>
<li>3333333</li>
<li>4444444</li>
</ul>
</body>
</html>


Top