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

老师,请问为什么新增的行取消勾选后,全选项无法自动取消勾选?我自己写的和老师的案例也是这样,请问是哪里有问题?

$(function(){
	/*************全选***********************/
	$("#chks").click(function(){
		var flag = $("#chks").prop("checked");
		$("input[name='chk']").prop("checked",flag);
	})
	/*************判断是否全选*****************/
	$("input[name='chk']").click(function(){
		var flag = true;
		
		var ck = $("input[name='chk']");
		
		ck.each(function(){
			if(!$(this).prop("checked")){
				flag = false;
			}
		})
		$("#chks").prop("checked",flag);
	})
	/************反选*******************/
	$("#fx").click(function(){
		var chk = $("input[name='chk']");
		
		chk.each(function(){
			var flag = $(this).prop("checked");
			$(this).prop("checked",!flag);
			
		})
		flag1 = true;
		chk.each(function(){
			if(!$(this).prop("checked")){
				flag1 = false;
			}
		})
		$("#chks").prop("checked",flag1);
	})
	
	/************新增一行*********************/
	$("#addRow").click(function(){
		var tb = $("#ta");
		tb.append('<tr id="">'+
				'<td><input type="checkbox" name="chk" id="" value="2"/></td>'+
				'<td>《Java编程之道》</td>'+
				'<td>wollo</td>'+
				'<td>10</td>'+
			'</tr>')
	})
	
	/************删除行**********************/
	$("#delRow").click(function(){
		var ck = $("input[name=chk]:checked");
		if(ck.length==0){
			alert("请至少选择一行");
		}else{
			ck.parent().parent().remove();
		}
	})
	
	
	
	/***************复制行********************/
	$("#copyRow").click(function(){
		var ck = $("input[name='chk']:checked");
		var tb = $("#ta");
		if(ck.length==0){
			alert("请选择至少一行");
		}else{
			tb.append(ck.parent().parent().clone());
		}
		
	})
	
})


JAVA 全系列/第四阶段:网页编程和设计/Jquery(旧) 21002楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:基于json数据格式完成商品规格参数模板管理 21003楼
Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 21004楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        a{
            text-decoration: none;
        }
        .box1,.top,.bottom{
            width: 100%;
        }
        .box{
            height: 1005px;
        }
        .center{
            width: 1240px;
            height: 1005px;
            background-color:#807e73;
            margin: 0 auto;
            text-align: center;
        }
        .top{
            height: 610px;
        }
        .bottom{
            height: 375px;
        }
        .top>div{
            width: 615px;
            height: 610px;
            float: left;
            margin-top: 10px;
            border-bottom:10px;
            background-color: azure;

        }
        .top-lift,.bottom1,.bottom2,.bottom3 {
            margin-right: 9px;
        }
        .bottom>div{
            width: 303px;
            height: 375px;
            float: left;
            margin-top: 10px;
            background-color: azure;
        }
        .ptop1{
           color: #333;
            font-size: 28px;
        }
        .ptop2{
            color: #333;
            font-size: 18px;
        }
        .ptop3{
            color: #c00;
            font-size: 22px;
        }
        .sptop1{
            font-size: 14px;
        }
        .imgtop{
            width: 460px;
            height: 460px;
            padding-top: px;
        }
        .imgbottom{
            width: 230px;
            height: 230px;
        }
        .pbottom1{
            color: #333;
            font-size: 16px;

        }
        .pbottom2{
            color: #999;
            font-size: 14px;

        }
        .pbottom3{
            color: #c00;
            font-size: 22px;

        }
        .spanbottom{
            font-size: 14px;
        }

    </style>
</head>
<body>
<div class="box1">
    <div class="center">
        <div class="top">
            <div class="top-lift">
                <a href="https://detail.meizu.com/item/meizu18.html" target="_blank">
                    <p class="ptop1">魅族 18</p>
                    <p class="ptop2">限时领券立省200 | 赠液态壳</p>
                    <p class="ptop3"><span class="sptop1">¥</span>3999</p>
                    <img src="meizu1.png" alt="魅族" title="魅族" class="imgtop" pos/>
                </a>
            </div>
            <div class="top-right">
                <a href="https://detail.meizu.com/item/meizu18pro.html" target="_blank">
                    <p class="ptop1">魅族 18 Pro</p>
                    <p class="ptop2">限时领券立省300 | 赠液态壳</p>
                    <p class="ptop3"><span class="sptop1">¥</span>4999</p>
                    <img src="meizu2.png" alt="魅族" title="魅族" class="imgtop"/>
                </a>
            </div>

        </div>
        <div class="bottom">
            <div class="bottom1">
                <a href="https://detail.meizu.com/item/meizu17.html" target="_blank">
                    <img src="meizu3.png" alt="魅族" title="魅族" class="imgbottom" />
                    <p class="pbottom1">魅族 17「AG梦幻独角兽」</p>
                    <p class="pbottom2">高通骁龙 865 | 120 Hz尝鲜模式</p>
                    <p class="pbottom3"><span class="spanbottom">¥</span>3699</p>

                </a>
            </div>
            <div class="bottom2">
            <a href="https://detail.meizu.com/item/meizu17.html" target="_blank">
                <img src="meizu4.png" alt="魅族" title="魅族" class="imgbottom" />
                <p class="pbottom1">魅族 17「松深入墨」</p>
                <p class="pbottom2">高通骁龙 865 | 120 Hz尝鲜模式</p>
                <p class="pbottom3"><span class="spanbottom">¥</span>3699</p>
            </a>
            </div>
            <div class="bottom3">
                <a href="https://detail.meizu.com/item/meizu17pro.html" target="_blank">
                    <img src="meizu5.png" alt="魅族" title="魅族" class="imgbottom" />
                    <p class="pbottom1">魅族 17 Pro「定白」</p>
                    <p class="pbottom2">限时领券至高立省1200+12期免息</p>
                    <p class="pbottom3"><span class="spanbottom">¥</span>4299</p>
                </a>
            </div>
            <div class="bottom4">
                <a href="https://detail.meizu.com/item/meizu17pro.html" target="_blank">
                    <img src="meizu6.png" alt="魅族" title="魅族" class="imgbottom" />
                    <p class="pbottom1">魅族 17 Pro「乌金</p>
                    <p class="pbottom2">限时领券至高立省1200+12期免息</p>
                    <p class="pbottom3"><span class="spanbottom">¥</span>4299</p>
                </a>
            </div>
        </div>



    </div>
</div>
</body>
</html>


WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 21005楼



    
    Title
    
        {
            : ;
        }
        .,.,.{
            : %;
        }
        .{
            : ;
        }
        .{
            : ;
            : ;
            :;
            : ;
            : ;
        }
        .{
            : ;
        }
        .{
            : ;
        }
        .>{
            : ;
            : ;
            : ;
            : ;
            :;
            : ;

        }
        .,.,.,.{
            : ;
        }
        .>{
            : ;
            : ;
            : ;
            : ;
            : ;
        }
        .{
           : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
        }
        .{
            : ;
            : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
            : ;

        }
        .{
            : ;
            : ;

        }
        .{
            : ;
            : ;

        }
        .{
            : ;
        }

    



    
        
            
                
                    18
                    200 | 
                    3999
                    
                
            
            
                
                    18 Pro
                    300 | 
                    4999
                    
                
            

        
        
            
                
                    
                    17AG
                    865 | 120 Hz
                    3699

                
            
            
            
                
                17
                865 | 120 Hz
                3699
            
            
            
                
                    
                    17 Pro
                    1200+12
                    4299
                
            
            
                
                    
                    17 Pro
                    1200+12
                    4299


WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 21006楼



    
    Title
    
        {
            : ;
        }
        .,.,.{
            : %;
        }
        .{
            : ;
        }
        .{
            : ;
            : ;
            :;
            : ;
            : ;
        }
        .{
            : ;
        }
        .{
            : ;
        }
        .>{
            : ;
            : ;
            : ;
            : ;
            :;
            : ;

        }
        .,.,.,.{
            : ;
        }
        .>{
            : ;
            : ;
            : ;
            : ;
            : ;
        }
        .{
           : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
        }
        .{
            : ;
            : ;
            : ;
        }
        .{
            : ;
            : ;
        }
        .{
            : ;
            : ;

        }
        .{
            : ;
            : ;

        }
        .{
            : ;
            : ;

        }
        .{
            : ;
        }

    



    
        
            
                
                    18
                    200 | 
                    3999
                    
                
            
            
                
                    18 Pro
                    300 | 
                    4999
                    
                
            

        
        
            
                
                    
                    17AG
                    865 | 120 Hz
                    3699

                
            
            
            
                
                17
                865 | 120 Hz
                3699
            
            
            
                
                    
                    17 Pro
                    1200+12
                    4299
                
            
            
                
                    
                    17 Pro
                    1200+12
                    4299

blob.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/初识CSS 21007楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 21009楼
WEB前端全系列/第十九阶段:Vue2知识体系(旧)/Vue基础知识 21010楼

老师,我这个打印不出来内容是为啥,看下面的评论说没联网,可是我网络也没问题啊

image.png代码:

from fake_useragent import UserAgent
import requests
from lxml import etree
from time import sleep


def get_html(url):
    '''
    :param url: 要爬取的地址
    :return: 返回html
    '''
    headers = {"User-Agent": UserAgent().chrome}
    resp = requests.get(url, headers=headers)
    # sleep(2)
    if resp.status_code == 200:
        resp.encoding = 'utf-8'
        return resp.text
    else:
        return None


def parse_list(html):
    '''
    :param html: 传递进来一个有电影列表的html
    :return: 返回一个电影列表的url
    '''

    e = etree.HTML(html)
    list_url = ['http://maoyan.com{}'.format(url) for url in e.xpath('//dd/div[@class="movie-item film-channel"]/a/@href')]
    return list_url


def pares_index(html):
    '''
    :param html: 传递进来一个有电影信息的html
    :return: 已经提取好的电影信息
    '''
    e = etree.HTML(html)
    name = e.xpath('//div/h1/text()')[0]
    type = e.xpath('//div/ul/li[@class="ellipsis"]/a/text()')[0]
    actors = e.xpath('//div[@class="celebrity-group"][2]/ul[@class="celebrity-list clearfix"]/li/div/a/text()')
    actors = format_data(actors)
    return {"name": name, "type": type, "actors": actors}


def format_data(actors):
    actor_set = set()
    for actor in actors:
        actor_set.add(actor.strip())
    return actor_set


def main():
    num = int(input('请输要获取多少页:'))
    for page in range(num):
        url = "https://maoyan.com/films?showType=3&offset={}".format(page*30)
        list_html = get_html(url)
        list_url = parse_list(list_html)
        for url in list_url:
            info_html = get_html(url)
            movie = pares_index(info_html)
            print(movie)


if __name__ == '__main__':
    main()


Python 全系列/第十四阶段:Python 爬虫开发/爬虫反反爬- 21012楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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