gpt4 book ai didi

javascript - 将静态 HTML 页面转换为动态生成的 jQuery

转载 作者:可可西里 更新时间:2023-11-01 14:47:06 24 4
gpt4 key购买 nike

我有一个奇怪的要求,我们有静态 html/css/图像。然后我需要将这些静态页面转换为使用 javascript/jquery 动态生成的页面。我们正在处理 100 多个此类实例。

例如:

<div id='foo' title='my title'>Hi there!</div>

将转换为:

$('<div/>', {
id: 'foo',
title: 'my title',
text: 'Hi there!'
}).appendTo('#mySelector');

有没有办法以编程方式执行此操作?我四处搜索,但找不到任何东西。

最佳答案

是这样的吗?

<div></div>

$('div').append('<p></p>');
$('div p').attr({
'id':'foo',
'title':'my title'
}).text('Hi there!');

输出:

<div><p id="foo" title="my title">Hi there!</p></div>

关于javascript - 将静态 HTML 页面转换为动态生成的 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28511627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com