日期:2014-05-16 浏览次数:20347 次
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="bootstrap/js/jquery.js"></script>
<script type="text/javascript">
var ds = ["武汉", "长沙", "上海", "北京", "广州", "深圳", "南京", "临安", "哈尔滨", "台南", "新竹", "台北", "花莲", "汴州"];
function cTb(ds, r, c) {
$("#tb_city").empty();
var tb = document.getElementById("tb"), L = ds.length, ii = 0;
for (var i = 0; i < r; i++) {
var row = tb.insertRow(-1);
for (var j = 0; j < c; j++) {
row.insertCell(-1).innerHTML = ds[ii++];
}
}
}
$(function () {
//$("#txt").focus(function () { //代码段 ①
// cTb(ds, 4, 3);
//});
cTb(ds, 4, 3); //代码段 ②
$("#tb td").click(function () {
var v = $(this).text();
$("#txt").val(v);
}).css("cursor", "pointer");
//cTb(ds, 4, 3); //代码段 ③
});
</script>
</head>
<body>
<div>
<table id="tb"></table>
</div>
<div>
<input type="text" id="txt" />
</div>
</body>
</html>