python获取html动态页面内容,动态HTML页面内容

首先,没有正确的方法。

你这样做很好。

也就是说,我不得不用JavaScript创建很多次内容,所以我想出了一个生成内容的函数。它可以很容易地修改,我发现它保持代码,imo,更干净。在function createElement(element, attributes, text) {

// function to create an element with class and text if wanted.

// attributes is an object of key value items. Key is the attribute, value is the value.

// you could change the "class" to an argument and use it to set anyAttribute

var el = document.createElement(element);

$.each(attributes, function(key, value) {

el.setAttribute(key, value);

});

if (text) {

var t = document.createTextNode(text);

el.appendChild(t);

}

return el;

}

举个例子,可以这样称呼:

^{pr2}$

这将创建以下元素

remove item

您仍然需要用JavaScript构建元素并将它们附加到DOM中,这需要一些工作,但我发现它有助于DRY。在

另一方面,你可以像@或Duan所说的那样,使用前端框架,或者使用前端模板引擎。

框架通常在中包含模板引擎和数据绑定值,以便它们在值更改时发生更改,但您可以自己执行逻辑,只需在框架外部使用模板引擎。

根据您的需要,有多种模板引擎-https://garann.github.io/template-chooser/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值