会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132906个问题

问题一:

老师,我想在点击新增一行这个按钮时新增的一行可以自定义书名,作者,数量,但是我发现我写的代码只能自定义书名和作者,而且数量随着书名和作者的值变化而变化,如果先在书名里面写张三那么数量也变为张三,然后在作者里面写李四,这时候数量又变成了李四,老师这个我该怎么解决


问题二:

我在书名,作者和数量的input里面都调用了失去焦点的方法,为什么只有数量可以成功调用,写完之后鼠标点击其他地方文本框边框消失,而作者和书名却不行


问题动图如下:


GIF.gif



源码如下:


html:

<html>
	<head>
		<title>jQuery操作表格</title>
		<meta charset="UTF-8"/>
		<!--声明css代码域-->
		<style type="text/css">
			tr{
				height: 40px;
			}
		</style>
	 
	 	<script src="js/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
		
		<script src="js/gwc.js"	type="text/javascript" charset="UTF-8"></script>
		
	</head>
	<body>
		<h3>jQuery操作表格</h3>
		<hr />
		<input type="button" id="fx" value="反选" />
		<input type="button" id="addRow" value="新增一行" />
		<input type="button" id="delRow" value="删除行" />
		<input type="button" id="copyRow" value="复制行" />
		<table border="1px" cellpadding="10px" cellspacing="0" id="ta">
			<tr>
				<td width="50px"><input type="checkbox" name="chks" id="chks" value="1" /></td>
				<td width="200px">书名</td>
				<td width="200px">作者</td>
				<td width="200px">数量</td>
				<td width="200px">操作</td>
			</tr>
			<tr id="">
				<td><input type="checkbox" name="chk" id="" value="2"/></td>
				<td>《Java编程之道》</td>
				<td>wollo</td>
				<td>10</td>
				<td>
					<input type="button" name="aa" id="" value="修改数量"  onclick="change(this)"/>
					<input type="button" name="" id="" value="删除" onclick="del(this)"/>
				</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="chk" id="" value="3" /></td>
				<td>《Python和我的故事》</td>
				<td>赵老师</td>
				<td>10</td>
				<td>
					<input type="button" name="" id="" value="修改数量" onclick="change(this)"/>
					<input type="button" name="" id="" value="删除" onclick="del(this)"/>
				</td>
			</tr>
			<tr>
				<td><input type="checkbox" name="chk" id="" value="4" /></td>
				<td>《web开发详解》</td>
				<td>张老师</td>
				<td>30</td>
				<td>
					<input type="button" name="" id="" value="修改数量" onclick="change(this)"/>
					<input type="button" name="" id="" value="删除" onclick="del(this)"/>
				</td>
			</tr>			
		</table>
	</body>
</html>


JS:

$(function(){
	
	//确定全选和全部不选操作
	
	$("#chks").click(function(){
		
		var flag = $(this).prop("checked");//返回布尔类型
		
			$("input[name=chk]").prop("checked",flag);//让所有内容都选中

	})
	
	//判断是否全选的操作
	$("input[name=chk]").click(function(){
		
		var flag = true;
		
		var chk = $("input[name=chk]");
		
		//each:遍历		每次遍历执行funaction 里面的内容
		chk.each(function(){
			
			if(!$(this).prop("checked")){
				
				flag = false;
				
				return;
			}
			
		})
		
		$("#chks").prop("checked",flag);
		
	})
	
	//反选的操作
	$("#fx").click(function(){
		
		//拿到所有的多选框
		var chx = $("input[name=chk]");
		
		//遍历
		chx.each(function(){
			
			//获得每个多选框的初始状态
			var flag = $(this).prop("checked");
			
			//现有状态与原始状态进行取反
			$(this).prop("checked",!flag);
		})
	})
	
	//新增加一行的操作
	$("#addRow").click(function(){
		
		//获得tab对象
		var tab = $("#ta");
		
		tab.append('<tr id="">'+
				'<td><input type="checkbox" name="chk" id="" value="2"/></td>'+
				'<td><input type="text"	onblur="bul(this)"/></td>'+
				'<td><input type="text"	onblur="bul(this)"/></td>'+
				'<td><input type="text"	onblur="bul(this)"/></td>'+
				'<td>'+
					'<input type="button" name="aa" id="" value="修改数量"  onclick="change(this)"/>&nbsp'+
					'<input type="button" name="" id="" value="删除" onclick="del(this)"/>'+
				'</td>'+
			'</tr>');
		
	})
	
	//删除的操作
	$("#delRow").click(function(){
		
		//获得被选中的name=chk的单选框
		var del = $("input[name=chk]:checked");
		
		if(del.length==0){//如果一行没选
			alert("至少选择一行!");
		}else{
			
			//执行删除整行的操作	单选框的父节点是	td	,	td	的父节点是	tr
			del.parent().parent().remove();
		}
		
	})
	
	//复制行		选中几个复制几个
	$("#copyRow").click(function(){
		
		//获得被选中的name=chk的多选框
		var copy = $("input[name=chk]:checked");
		
		if(copy.length==0){//如果一行没选
			alert("至少选择一行!");
		}else{
			//执行copy的操作
			
			//复制
			var tr = copy.parent().parent().clone();//克隆整行
			//黏贴
			$("#ta").append(tr);
			
		}
	})
	
})

//修改数量的操作

function change(th){//这里的this是JS类型的,得转换成JQ对象
	
	//$(th):转换成JQ对象		获得	tr	结点
	var par = $(th).parent().parent();
	
	//将写死的数量变成可以定义的文本框
	par.children().eq(3).html("<input	type='text' size='3px' onblur='bul(this)'/>");
}

function bul(th){
	
	var par = $(th).parent().parent();
	
	par.children().eq(3).html(th.value);//或者转成JQ对象再调用val来获得值
}

function del(th){
	
	var par = $(th).parent().parent();
	
	par.remove();
	
}


JAVA 全系列/第四阶段:网页编程和设计/Jquery(旧) 5431楼
JAVA 全系列/第三阶段:数据库编程/MySQL数据库 5433楼
Python 全系列/第七阶段:网页编程基础/jquery 5436楼

分享,解决centos6.8上安装Twisted-19.7.0报错"ModuleNotFoundError: No module named '_ctypes'"的方法考网上解决办法:

  1. 安装外部函数库(libffi)

    yum install libffi-devel -y
  2. 重新安装python

  3. 用pip3 Install 安装需要的包

    再次报错:distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')

参考网上解决办法:

yum install -y epel-release
yum install -y python-pip
pip3 install incremental -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
cd Twisted-19.7.0
python3 setup.py install

再次报错:error: Could not find suitable distribution for Requirement.parse('attrs>=17.4.0')

解决办法

pip3 install attrs -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
cd Twisted-19.7.0
python3 setup.py install

再次报错:error: Could not find suitable distribution for Requirement.parse('PyHamcrest>=1.9.0')

pip3 install PyHamcrest -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
cd Twisted-19.7.0
python3 setup.py install

再次报错:error: Could not find suitable distribution for Requirement.parse('hyperlink>=17.1.1')

pip3 install hyperlink -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
cd Twisted-19.7.0
python3 setup.py install

再次报错:error: Could not find suitable distribution for Requirement.parse('Automat>=0.3.0')

pip3 install Automat -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install constantly -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install zope.interface -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
cd Twisted-19.7.0
python3 setup.py install

执行上述操作后:linux界面提示Finished processing dependencies for Twisted==19.7.0



Python 全系列/第十四阶段:Python 爬虫开发/分布式爬虫 5437楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 5438楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6 第一部分 5439楼
JAVA 全系列/第八阶段:SpringBoot与MybatisPlus/Spring Boot(旧) 5440楼
JAVA 全系列/第二十九阶段:数据结构和算法BATJ大厂面试重难点/字符串和矩阵 5441楼
Python 全系列/第十一阶段:重量级Web框架-Django/Redis的入门与应用(拓展) 5444楼
JAVA 全系列/第三阶段:数据库编程/Oracle 数据库的使用 5445楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637