页面异步保存列表列

需求

1. 客户有一个需要,需要在列表页面中的某一列直接进行修改操作。如下:需要修改"实地落地"这一列。



实现

1 基本想法就是使用jquery的插件,所以经过一些筛选找到了joytech这个组件,并且进行了一些二次开发。

1 引用js

<script language="javascript" type="text/javascript" src="${cssPath}/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" language="javascript" src="${cssPath}/js/jquery.joytech.core.js"></script>
<script type="text/javascript" language="javascript" src="${cssPath}/js/jquery.joytech.editable.js"></script>

2 列表定义

定义一个class为 editable,用于对列进行选择(方便使用jquery选择器)

<div class="w100 editable" onClick="{currId='${ts.id}'}" > ${ts.realityLandingTime}  </div>

3 代码实现

var currId = "";
function submitDo(oldValue,changeValue){
	//alert(oldValue);
	//alert(changeValue);
	// alert("submitDo1..." + currId + " "+changeValue);
	if(oldValue==changeValue){
		return;
	}
	$.ajax({  
       url:'/flight34/train/updateRealityLandingTime.do',  
       //url:'${ctx}/index.jsp',  
       async:false,
       cache:false,  
       type:'post',  
       dataType:'html',      
       data:{   
    	   tsid:currId,
    	   realityLandingTime:changeValue,
   		   contentType: "application/x-www-form-urlencoded;charset=utf-8"  
       },  
       success:function(html){  
    	   // alert(html)
    	   $("#warn").html("操作成功");
		   fail();
       }  
   });  	
	
}

$(document).ready(function () {
	if($("#phase").val()==9){
		$(".editable").editableText(submitDo);	
	}
});


依赖js文件 

备注:这里我对joytech做过二次开发,主要是添加了异步提交方法

jquery.joytech.core.js

(function ($, undefined) {

    $.joytech = $.joytech || {};

})(jQuery);

jquery.joytech.editable.js

/*!
* jQuery joytech editable 1.0.0
*
*
* Depends:
*	jquery.joytech.core.js
*/
(function ($) {

    $.joytech._editable = {

        _editor: null,
        _richeditor: null,
        _currenteditor: null,
        _holder: null,
		_submit: null,

        _blur: function (event) {

            var pthis = $.joytech._editable;
            if (pthis._holder) {
                var e = $(pthis._holder);
                switch (e.attr("joytech_editable_type")) {
                    case 'text': e.text(pthis._currenteditor.value); break;
                    case 'html': e.html(pthis._currenteditor.value); break;
                    case 'value': e.val(pthis._currenteditor.value); break;
                }
                pthis._holder = null;

                $(pthis._currenteditor).hide();
            }
            // alert("...");
			$.joytech._editable._submit(pthis._currenteditor.oldValue,pthis._currenteditor.value);
            return false;
			
        },

        _click: function (event) {
            var pthis = $.joytech._editable;
            if (pthis._editor == null) {
                $(document.body).append("<input type='text' style='position:absolute;' id='joytech__editable__editor'/>");
                pthis._editor = $('#joytech__editable__editor')[0];
                $(pthis._editor).blur($.joytech._editable._blur).hide();
            }
            if (pthis._richeditor == null) {
                $(document.body).append("<textarea style='position:absolute;' id='joytech__editable__richeditor'/>");
                pthis._richeditor = $('#joytech__editable__richeditor')[0];
                $(pthis._richeditor).blur($.joytech._editable._blur).hide();
            }
            pthis._holder = event.target;
            var e = $(event.target);

            var bricheditor = (e.attr("joytech_editable_type")) == 'html' && (e.attr("joytech_editable_usingricheditor")=='true');
            if (bricheditor) pthis._currenteditor = pthis._richeditor;
            else pthis._currenteditor = pthis._editor;

            var i = $(pthis._currenteditor);

            var value = '';
            switch (e.attr("joytech_editable_type")) {
                case 'text': value = e.text(); break;
                case 'html': value = e.html(); break;
                case 'value': value = e.val(); break;
            }

            if (bricheditor) i.val(value);
            else i.val(value);            
            pthis._currenteditor.oldValue =  value;
            
            var o = e.offset();
            i.css({
                left: o.left,
                top: o.top,
                width: e.width(),
                height: e.height()
            }).show().focus();
            return false;
        }

    };

    $.fn.editableHTML = function (usingricheditor) {
        this.attr("joytech_editable_type", "html");
        this.attr("joytech_editable_usingricheditor", usingricheditor);
        this.dblclick($.joytech._editable._click);
        return $;
    };

    $.fn.editableText = function (submitFunc) {
		$.joytech._editable._submit = submitFunc;
        this.attr("joytech_editable_type", "text");
        this.dblclick($.joytech._editable._click);
        return $;
    };

    $.fn.editableValue = function () {
        this.attr("joytech_editable_type", "value");
        this.click($.joytech._editable._click);
        return $;
    };

})(jQuery);


import time import openpyxl from selenium import webdriver from bs4 import BeautifulSoup # 设置请求头,模拟真实浏览器访问 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', } # 使用Selenium启动浏览器 driver = webdriver.Chrome() data = [] counter = 1 # 序号计数器 # 打开网页 for i in range(1,6): url = 'https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&psort=3&wq=%E6%89%8B%E6%9C%BA&psort=3&pvid=0faa3ec65d444d68a66161cdf464d451&psort=3&page={}&s=61&click=0'.format( (i * 2) - 1) driver.get(url) # 模拟滚动页面,以触发异步请求加载更多商品信息 driver.execute_script('window.scrollTo(0, document.body.scrollHeight);') time.sleep(2) # 获取完整页面内容 html = driver.page_source # 解析网页内容,提取商品名称和价格信息 soup = BeautifulSoup(html, 'html.parser') products = soup.select('.gl-item') for product in products: product_id = product['data-sku'] # 提取产品ID name = product.select('.p-name em')[0].text.strip() product_url = 'https:' + product.select('.p-name a')[0]['href'] # 修改产品URL price = product.select('.p-price strong i')[0].text.strip() data.append([counter, product_id, name, product_url, price]) # 将产品数据添加到列表中 counter += 1 # 每个产品的增量计数器 # 关闭浏览器 driver.quit() # 创建Excel文件并保存数据 wb = openpyxl.Workbook() ws = wb.active ws.append(['top', '商品ID', '商品名称', '商品链接', '价格']) # 添加已修改顺序的标题行 for item in data: ws.append(item) wb.save('jd_top300.xlsx') print("数据已保存到jd_top300.xlsx文件。")
最新发布
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值