把jQuery代码改为js代码,代码如下, 5
<scripttype="text/javascript">$(function(){//创建变量var$name=$(".name"),$age=$(".age"),$...
<script type="text/javascript">
$(function(){
//创建变量
var $name = $(".name"),
$age = $(".age"),
$profession = $(".profession"),
$add_arr = $(".add_arr"),
$search_all = $(".search_all"),
$get_name = $(".get_name"),
$get_age = $(".get_age"),
$get_profession = $(".get_profession"),
$show_data = $(".show_data"),
$show_name = $(".show_name"),
$show_age = $(".show_age"),
$show_profession = $(".show_profession"),
input_arr = [];
//创建对象
var form_handle = {
// 获取表单数据
getInput : function(){
return [$name.val(), $age.val(), $profession.val()];
},
// 定义初始化方法
init : function(){
var self = this;
$add_arr.on('click', function(){
self.confirm(function(that){
that.addArray();
});
});
$search_all.on('click', function(){
self.showData();
});
$get_name.on('click', function(){
self.getName();
});
$get_age.on('click', function(){
self.getAge();
});
$get_profession.on('click', function(){
self.getProfession();
});
},
// 显示数据
showData : function(){
var arr = [];
arr = this.getSort(0);
$show_data.find('tr:gt(0)').remove();
for(var i = 0; i < arr.length; i ++){
var tpl = [
' <tr>',
' <td>' + arr[i][0] + '</td>',
' <td>' + arr[i][1] + '</td>',
' <td>' + arr[i][2] + '</td>',
' </tr>'
].join("");
$show_data.append(tpl);
}
},
// 获取姓名
getName : function(){
var str = "";
var arr = [];
for(var i = 0; i < input_arr.length; i ++){
arr.push(input_arr[i][0]);
}
str = arr.join(" = ");
$show_name.text("姓名: " + str);
},
})
</script> 展开
$(function(){
//创建变量
var $name = $(".name"),
$age = $(".age"),
$profession = $(".profession"),
$add_arr = $(".add_arr"),
$search_all = $(".search_all"),
$get_name = $(".get_name"),
$get_age = $(".get_age"),
$get_profession = $(".get_profession"),
$show_data = $(".show_data"),
$show_name = $(".show_name"),
$show_age = $(".show_age"),
$show_profession = $(".show_profession"),
input_arr = [];
//创建对象
var form_handle = {
// 获取表单数据
getInput : function(){
return [$name.val(), $age.val(), $profession.val()];
},
// 定义初始化方法
init : function(){
var self = this;
$add_arr.on('click', function(){
self.confirm(function(that){
that.addArray();
});
});
$search_all.on('click', function(){
self.showData();
});
$get_name.on('click', function(){
self.getName();
});
$get_age.on('click', function(){
self.getAge();
});
$get_profession.on('click', function(){
self.getProfession();
});
},
// 显示数据
showData : function(){
var arr = [];
arr = this.getSort(0);
$show_data.find('tr:gt(0)').remove();
for(var i = 0; i < arr.length; i ++){
var tpl = [
' <tr>',
' <td>' + arr[i][0] + '</td>',
' <td>' + arr[i][1] + '</td>',
' <td>' + arr[i][2] + '</td>',
' </tr>'
].join("");
$show_data.append(tpl);
}
},
// 获取姓名
getName : function(){
var str = "";
var arr = [];
for(var i = 0; i < input_arr.length; i ++){
arr.push(input_arr[i][0]);
}
str = arr.join(" = ");
$show_name.text("姓名: " + str);
},
})
</script> 展开
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>checkbox</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script src="js/1.js" type="text/javascript"></script>
</head>
<body>
<table id="table1">
<tr>
<td><input type="checkbox" value="1"/>1</td>
<td id="k_1"><input type="text" name="student" id="s_1" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="2"/>2</td>
<td id="k_2"><input type="text" name="student" id="s_2" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="3"/>3</td>
<td id="k_3"><input type="text" name="student" id="s_3" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="4"/>4</td>
<td id="k_4"><input type="text" name="student" id="s_4" readonly="true"/></td>
</tr>
</table>
</body>
</html>
-------------------------------------------------------------
$(document).ready(function() {
$("td[id^='k_']").hide();
var check = $(":checkbox"); //得到所有被选中的checkbox
var actor_config; //定义变量
check.each(function(i){
actor_config = $(this);
actor_config.click(
function(){
if($(this).attr("checked")==true){
$("#k_"+$(this).val()).show();
}else{
$("#k_"+$(this).val()).hide();
}
}
);
});
});
<html>
<head>
<title>checkbox</title>
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script src="js/1.js" type="text/javascript"></script>
</head>
<body>
<table id="table1">
<tr>
<td><input type="checkbox" value="1"/>1</td>
<td id="k_1"><input type="text" name="student" id="s_1" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="2"/>2</td>
<td id="k_2"><input type="text" name="student" id="s_2" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="3"/>3</td>
<td id="k_3"><input type="text" name="student" id="s_3" readonly="true"/></td>
</tr>
<tr>
<td><input type="checkbox" value="4"/>4</td>
<td id="k_4"><input type="text" name="student" id="s_4" readonly="true"/></td>
</tr>
</table>
</body>
</html>
-------------------------------------------------------------
$(document).ready(function() {
$("td[id^='k_']").hide();
var check = $(":checkbox"); //得到所有被选中的checkbox
var actor_config; //定义变量
check.each(function(i){
actor_config = $(this);
actor_config.click(
function(){
if($(this).attr("checked")==true){
$("#k_"+$(this).val()).show();
}else{
$("#k_"+$(this).val()).hide();
}
}
);
});
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询