[Source Code] Using JavaScript to manipulate DOM

数据资产目录(SailCatalog)和数据地图(SailMap) 笔者接下来准备开发大数据平台(XSailboat)中的数据资产目录(SailCatalog)和数据地图(SailMap)相关的功能,本文用以记录笔者关于此部分功能的概念梳理和主体功能设计。 阅读详情

An Introduction to the Document Object Model
The DOM is a standard way of representing XML documents (instituted by the W3C). It is
not necessarily the fastest, lightest, or easiest to use, but it is the most ubiquitous, with an
implementation existing in most web development programming languages (such as Java,
Perl, PHP, Ruby, Python, and JavaScript). The DOM was constructed to provide an intuitive
way for developers to navigate an XML hierarchy. Even if you’re not completely familiar with
XML, you will get great satisfaction knowing that all HTML documents (which are, in the
eyes of the browser, XML documents) have a DOM representation that is ready to use. 

Pro JavaScript™ Techniques, Apress
Copyright © 2006 by John Resig

 

 <html id="html">
<head id="head">
<title id="title">Introduction to the DOM</title>

<script id="script">

function displayNode( elem ){
//get all text in an elem
elem.innerText;

//get text of a node
elem.nodeValue;

//get HTML in an elem
elem.innerHTML;
}

function test(){
//alert("worked");
//alert(document.documentElement.name);
//var ret = last(document.documentElement);
var ret = "sss"//tag("input")[0];
//alert(ret.constructor== String );

append( tag("ol")[0], "<li>Mouse trap.</li>" );


var li = document.getElementsByTagName("li");
for ( var j = 0; j < li.length; j++ ) {
li[j].style.border = "1px dotted #000";
}

//document.getElementById("everywhere").style.fontWeight = 'bold';
//var ret2 = document.getElementById("head");
//alert(ret2.id);
}

//Finding the Previous Sibling Element in Relation to an Element
function prev( elem ) {
do {
elem = elem.previousSibling;
} while ( elem && elem.nodeType != 1 );
return elem;
}

//Finding the Next Sibling Element in Relation to an Element
function next( elem ) {
do {
elem = elem.nextSibling;
} while ( elem && elem.nodeType != 1 );
return elem;
}

//Finding the First Child Element of an Element
function first( elem ) {
elem = elem.firstChild;
return elem && elem.nodeType != 1 ?
next ( elem ) : elem;
}

//Finding the Last Child Element of an Element
function last( elem ) {
elem = elem.lastChild;
return elem && elem.nodeType != 1 ?
prev ( elem ) : elem;
}

//Finding the Parent of an Element
// parent(elem, 2) == parent( parent(elem) )
function parent( elem, num ) {
num = num || 1;
for ( var i = 0; i < num; i++ )
if ( elem != null ) elem = elem.parentNode;
return elem;
}

//Locating Elements by Id Within an HTML DOM Document
function id(name) {
return document.getElementById(name);
}

//Locating Elements by Tag Name Within an HTML DOM Document
function tag(name, elem) {
// If the context element is not provided, search the whole document
return (elem || document).getElementsByTagName(name);
}

//Searches for All Elements That Have a Particular Class Name
function hasClass(name,type) {
var r = [];
// Locate the class name (allows for multiple class names)
var re = new RegExp("(^|//s)" + name + "(//s|$)");
alert(re);
// Limit search by type, or look through all elements
var e = document.getElementsByTagName(type || "*");
alert("eeee-->"+e.length);
for ( var j = 0; j < e.length; j++ )
// If the element has the class, add it for return
if ( re.test(e[j].className) ) r.push( e[j] );

// Return the list of matched elements
return r;
}

//A Generic Function for Retreiving the Text Contents of an Element
//including all contents of its children Elements
function text(e) {
var t = "";
// If an element was passed, get its children,
// otherwise assume it's an array
e = e.childNodes || e;
// Look through all child nodes
for ( var j = 0; j < e.length; j++ ) {
// If it's not an element, append its text value
// Otherwise, recurse through all the element's children
t += e[j].nodeType != 1 ?
e[j].nodeValue : text(e[j].childNodes);
}
// Return the matched text
return t;
}

//Determining Whether an Element Has a Certain Attribute
function hasAttribute( elem, name ) {
return elem.getAttribute(name) != null;
}

/*
Getting and Setting the Values of Element Attributes

Calling the function with two parameters, for example attr(element, id), returns
that value of that attribute. Calling the function with three parameters, such as attr(element,
class, test), will set the value of the attribute and return its new value. 


Usage Examples:
// Set the class for the first <h1> Element
attr( tag("h1")[0], "class", "header" );
// Set the value for each <input> element
var input = tag("input");
for ( var i = 0; i < input.length; i++ ) {
attr( input[i], "value", "" );
}
// Add a border to the <input> Element that has a name of 'invalid'
var input = tag("input");
for ( var i = 0; i < input.length; i++ ) {
if ( attr( input[i], "name" ) == 'invalid' ) {
input[i].style.border = "2px solid red";
}
}
*/
function attr(elem, name, value) {
// Make sure that a valid name was provided
if ( !name || name.constructor != String ) return '';
// Figure out if the name is one of the weird naming cases
name = { 'for': 'htmlFor', 'class': 'className' }[name] || name;
// If the user is setting a value, also
if ( typeof value != 'undefined' ) {
// Set the quick way first
elem[name] = value;
// If we can, use setAttribute
if ( elem.setAttribute )
elem.setAttribute(name,value);
}
// Return the value of the attribute
return elem[name] || elem.getAttribute(name) || '';
}

/*
The following are functions to manipulate DOM object
including create/insert/delete nodes

Usage:
1. Basic append
// Create a new <li> element
var li = create("li");
attr( li, "class", "new" );
// Create some new text contents and add it to the <li>
append( li, "Thanks for visiting!" );
// Add the <li> onto the top of the first Ordered List
if( first(tag("ol")[0]) == null ){
 //elem 'ol' has no child
 append( tag("ol")[0], li);
}else{
 before( first( tag("ol")[0] ), li );
}

2. Enhance Version of append and insert
append( tag("ol")[0], "<li>Mouse trap.</li>" );

*/

/*
A Generic Function for Creating a New DOM Element

Usage:
var div = create("div");
div.className = "items";
div.id = "all";
*/
function create( elem ) {
return document.createElementNS ?
document.createElementNS( 'http://www.w3.org/1999/xhtml', elem ) :
document.createElement( elem );
}

/*
Basic Version for Inserting and Appending into the DOM

function before( parent, before, elem ) {
// Check to see if no parent node was provided
if ( elem == null ) {
elem = before;
before = parent;
parent = before.parentNode;
}
parent.insertBefore( checkElem( elem ), before );
}

function append( parent, elem ) {
parent.appendChild( checkElem( elem ) );
}

function checkElem( elem ) {
// If only a string was provided, convert it into a Text Node
return elem && elem.constructor == String ?
document.createTextNode( elem ) : elem;
}
*/
//Enhanced Functions for Inserting and Appending into the DOM
function before( parent, before, elem ) {
// Check to see if no parent node was provided
if ( elem == null ) {
elem = before;
before = parent;
parent = before.parentNode;
}
// Get the new array of elements
var elems = checkElem( elem );
// Move through the array backwards,
// because we're prepending elements
for ( var i = elems.length - 1; i >= 0; i-- ) {
parent.insertBefore( elems[i], before );
}
}

function append( parent, elem ) {
// Get the array of elements
var elems = checkElem( elem );
// Append them all to the element
for ( var i = 0; i < elems.length; i++ ) {
parent.appendChild( elems[i] );
}
}

//Converting an Array of Mixed DOM Node/HTML String Arguments into a
//Pure Array of DOM Nodes
function checkElem(a) {
var r = [];
// Force the argument into an array, if it isn't already
if ( a.constructor != Array ) a = [ a ];
for ( var i = 0; i < a.length; i++ ) {
// If there's a String
if ( a[i].constructor == String ) {
// Create a temporary element to house the HTML
var div = document.createElement("div");
// Inject the HTML, to convert it into a DOM structure
div.innerHTML = a[i];
// Extract the DOM structure back out of the temp DIV
for ( var j = 0; j < div.childNodes.length; j++ )
r[r.length] = div.childNodes[j];
} else if ( a[i].length ) { // If it's an array
// Assume that it's an array of DOM Nodes
for ( var j = 0; j < a[i].length; j++ )
r[r.length] = a[i][j];
} else { // Otherwise, assume it's a DOM Node
r[r.length] = a[i];
}
}
return r;
}


/* Remove node
Usage:
// Remove the last <li> from an <ol>
remove( last( tag("ol")[0] ) )
// The above will convert this:
<ol>
<li>Learn Javascript.</li>
<li>???</li>
<li>Profit!</li>
</ol>
// Into this:
<ol>
<li>Learn Javascript.</li>
<li>???</li>
</ol>
// If we were to run the empty() function instead of remove()
empty( last( tag("ol")[0] ) )
// It would simply empty out our <ol>, leaving:
<ol></ol>
*/
// Remove a single Node from the DOM
function remove( elem ) {
if ( elem ) elem.parentNode.removeChild( elem );
}

// Remove all of an Element's children from the DOM
function empty( elem ) {
while ( elem.firstChild )
remove( elem.firstChild );
}

//--></script>

</head>
<body id="body">
<h1 id="h1">Introduction to the DOM</h1>
<p id="p" class="test">There are a number of reasons why the
DOM is awesome, here are some:</p>
<ul id="ul">
<li id="everywhere">It can be found everywhere.</li>
<li class="test" id="li2">It's easy to use.</li>
<li class="test" id="li3">It can help you to find what you want, really quickly.</li>
</ul>
<ol>

</ol>

<input id="input1" name="Submit" type="submit"  style = " width : 100  "class="" value="Test" onclick="test();">
</body>
</html>

 

UNet 改进(45):轻松集成Triplet Attention,让分割效果起飞! 本文介绍了一种在U-Net架构中集成CSRA残差注意力模块的方法。该模块通过结合通道注意力和空间注意力机制,在U-Net的瓶颈层对特征进行自适应重标定,使网络聚焦于关键区域。文章详细解析了代码实现,包括基础构建块DoubleConv、核心CSRA模块原理及其在U-Net中的战略位置集成。测试表明该模型能保持标准U-Net的输入输出维度,同时通过注意力机制提升特征选择能力。这种模块化设计便于在不同任务中应用,为图像分割领域提供了有效的注意力增强方案。 阅读详情

相关推荐

我的AI学习 ai维护工具之langfuse

as_type: Optional[Literal[‘generation’]] = None, # 将记录定义为 Observation (LLM 调用)transform_to_string: Optional[Callable[[Iterable], str]] = None # 将输出转为 string。要用LangFuse的云服务,首先要在LangFuse官网上注册,注册完后将页面拉倒最后,点免费的SignUp,API文档:https://api.reference.langfuse.com/

liubaobin的博客 4107

jquery 实现原理八:DOM操作-manipulate

jquery dom操作有很重要的一点就是对数组的操作,因为jquery的很多操作都是对当前选中的所有元素都起作用的。所以很自然的这个操作会被封装起来。 有两个重要函数会被频繁调用来进行dom操作,分别是domManip和access。 access功能比较简单,可以认为就是一个数组的foreach操作,只是做了一些小的改进:对value回调函数的支持和对链式操作的支持。 domMa

言川的博客 3056

【3D计算机视觉】从PointNet到PointNet++理论及pytorch代码

从PointNet到PointNet++理论及代码详解1. 点云是什么1.1 三维数据的表现形式1.2 为什么使用点云1.3 点云上以往的相关工作2. PointNet2.1 基于点云的置换不变性2.1.1 由对称函数到PointNet(vanilla)2.1.2 理论证明2.2 基于点云的旋转不变性2.3 网络总体结构2.4 实验结果和网络的鲁棒性2.5 代码解析3. PointNet++3.1...

小执着的博客 8万+

以标签名和内容得到的DOM

      代码function hasClass(name,type) {var r = [];// Locate the class name (allows for multiple class names)var re = new RegExp("(^|\\s)" + name + "(\\s|$)");// Limit search by type, or look through al...

weixin_34232363的博客 116

Ubuntu18.04下Carla安装——经验史

Ubuntu下的Carla安装

m0_51267207的博客 2685

ANSYS Fluent热边界条件避坑指南:为什么你的自然对流计算结果总出错?

本文深入剖析了在ANSYS Fluent中进行自然对流仿真时,导致计算结果出错或发散的核心原因与解决方案。重点解析了重力项与操作密度设置、Boussinesq与不可压缩理想气体模型的抉择、以及压力离散格式(推荐Body Force Weighted)这三大关键雷区,并结合电子机箱散热等实战案例,提供了一套稳定可靠的仿真设置流程与调试技巧。

weixin_28396629的博客 755

通过clss属性查找元素

function hasClass(name,type) { var r = []; // Locate the class name (allows for multiple class names) var re = new RegExp("(^|\\s)" + name + "(\\s|$)"); // Limit search by type...

modun1986的专栏 184

34、婴儿监视器应用开发指南

本文详细介绍了基于 ESP32 和 Edge Impulse 开发婴儿监视器应用的全过程,涵盖音频处理、机器学习推理、ESP RainMaker 平台集成以及内存监控等功能。通过实现 AppAudio、AppRmaker 和 AppMem 三个核心类,完成了婴儿哭声的实时检测与远程通知,并通过合理的内存管理优化,有效节省了 ESP32 的内部 RAM 资源。文章还提供了完整的代码示例和配置说明,适用于物联网和嵌入式 AI 应用开发爱好者参考学习。

python9snake的博客 96

解锁Obsidian表格编辑新境界:告别Markdown源码的束缚

还在为编辑复杂的Markdown表格而烦恼吗?每次调整列宽、添加行数,都要在源码中小心翼翼地修改那些竖线和横线,生怕一个空格就破坏了整个表格的结构。Obsidian Table Enhancer插件正是为了解决这一痛点而生,让你能够像操作Excel一样直观地编辑Markdown表格,彻底告别源码编辑的繁琐。 ## 三大核心痛点与智能解决方案 ### 痛点一:源码编辑效率低下 传统的Markdo

gitblog_00568的博客 340

飞牛fnNAS虚拟机标准安装

飞牛NAS是一款基于Debian开发的国产免费NAS系统,支持x86架构设备,可将闲置硬件改造为NAS服务器。系统安装简便,支持多种存储模式与硬盘休眠功能,具备智能影视管理、照片备份等实用功能,并提供多种远程访问方式。飞牛NAS还支持Docker扩展,目前已承诺永久免费。文章详细介绍了在VMware虚拟机中安装飞牛NAS的步骤,包括下载镜像、创建虚拟机、初始化设置等过程,并展示了创建共享文件夹等基本操作,帮助用户快速上手这款功能强大的免费NAS系统。

dgnankai的专栏 3281

基于libVLC的视频播放器之四:直接使用libVLC

一.效果 播放本地文件 播放网络url:rtsp://3.84.6.190/vod/mp4:BigBuckBunny_115k.mov 二.实现 既然有VLC-Qt,为什么还要直接调用libVLC呢,因为直接调用会加深对整个播放流程的理解,方便后面修改VLC-Qt源码。 注意事项: 1.编译报错:error C2065: “libvlc_media_read_cb”: 未声明的标识符。修改如下: 2.libvlc_new(0, nullptr)返回null 将plugins

草上爬的博客 5054

Obsidian 表格增强插件 Table Enhancer 完整指南:不碰源码,像用 Excel 一样编辑表格

你正盯着预览模式里一张项目进度表,想改掉其中一个数字。切到源码模式,光标在一堆 `|` 和空格之间小心游走,手一抖删掉了一个分隔符,整张表瞬间变成乱码——这种体验几乎每个 Obsidian 用户都经历过。**Table Enhancer(ob-table-enhancer)** 就是为解决这个问题而生的免费开源插件:它让你在预览模式下直接点击单元格编辑,像操作 Word 或 Excel 一样处理

gitblog_00276的博客 900

从零玩转Vitis裸机开发:手把手教你创建、移植与实战优化

✅ Vitis裸机开发全流程✅ 中断系统配置技巧✅ 跨平台移植方法论✅ 性能优化实战经验研究FreeRTOS移植探索AMP(非对称多处理)架构学习使用Vitis Analyzer进行性能分析技术雷达:关注Xilinx最新推出的Vitis Unified IDE,其集成了更强大的调试和分析工具。立即动手实践吧!

QQ_778132974的博客 586

[设计模式]DAO的实现方式探讨_Part II

Data Access Object PatternProblemYou want to encapsulate data access and manipulation in a separate layerForces You want to implement data access mechanisms to access and ma

Fitzwilliam的专栏 2074

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Savepoints In Transactions

Savepoints In TransactionsYou can declare intermediate markers called savepoints within the context of a transaction. Savepoints divide a long transaction into smaller parts.Using savepoints, yo

Fitzwilliam的专栏 1846

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

[读书笔记] 数据库设计基础

数据库效率的两个主要度量方法:吞吐量(throughput)——每单位时间里能够处理的查询或更新(通常指事务)的平均数量。响应时间(response time)——单个事务从开始到结束所需的平均时间或者最长时间。以批量的方式处理大量事务的系统关注于达到高吞吐量。与人交互或者时间苛刻的系统则通常关注于响应时间。大多数商业数据库系统长期以来都关注于吞吐量,但是,包括基于Web的应用和电信信

Fitzwilliam的专栏 1635

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

示例代码:如何正确close从连接池中取得的db连接

Here is an example of properly written code to use a db connection obtained from a connection pool: Connection conn = null; Statement stmt = null; // Or PreparedStatement if needed ResultSet

Fitzwilliam的专栏 1564

[读书笔记]网络协议 —————— TCP/IP

---------------------------------- IP ----------------------------------IP protocol:IP is the workhorse protocol of the TCP/IP protocol suite.  All TCP, UDP, ICMP and IGMP data gets transmitted as

Fitzwilliam的专栏 1558

[读书笔记]Test Strategy - Intruductions of Stub and Mock

Stubs are a mechanism for faking the behavior of real code that may exist or thatmay not have been written yet. Stubs allow you to test a portion of a system withoutthe other part being available. The

Fitzwilliam的专栏 1550

[书摘/Summary] Usage of Collections

Choosing between ListsThe best approach is probably to choose an ArrayList as your default and to change to a LinkedList if you discover performance problems due to many insertions and removals from

Fitzwilliam的专栏 1404

[设计模式]DAO的实现方式探讨_Part I

先说一下我的参考书目: Core J2EE™ Patterns: Best Practices and Design Strategies, Second Edition By Deepak Alur, John Crupi, Dan Malks Publisher : Prentice Hall PTR Pub Date : June 10, 2003 ISBN : 0-13-142246-4

Fitzwilliam的专栏 1399

[读书笔记]JAVA IO

Almost all of the original Java I/O stream classes have corresponding Reader and Writer classes to provide native Unicode manipulation. However, there are some places where the byte-oriented InputStre

Fitzwilliam的专栏 1229

sth about Inheritance

public  class Test extends Test2{ Test(String s) {  System.out.println(s);  }public static void main(String[] args)  {   Test t=new Test("Test");  }} class Test2{ Test2(String s) {  System.out.print

Fitzwilliam的专栏 1195

[读书笔记] Collections of objects

The Java 2 container library takes the issue of “holding your objects” and divides it into two distinct concepts: Collection: a group of individual elements, often with some rule applied to th

Fitzwilliam的专栏 1118

环信 GitHub 仓库索引——全部SDK、UIKit 与 CallKit、Demo 与集成示例

本文档汇总环信官方及社区GitHub仓库,涵盖多端IM SDK、UIKit、CallKit组件及完整Demo,支持iOS、Android、Flutter、React Native、HarmonyOS等平台,提供快速集成与开发参考。

huan132456765的博客 225

Three.js 后处理辉光 Bloom、告警发光效果、管线流光、着色器流动管线(ShaderMaterial)

告警辉光(Bloom):故障阀门、罐体外围柔和红光,一眼识别告警管线介质流动:管道内部流体顺着管道方向流动,模拟介质输送Bloom:后处理,屏幕空间泛光,适合设备告警;缺点是全局开销大,需要分层ShaderMaterial:着色器,在管线几何体上直接写流动动画,适合管道流光,性能可控避坑提醒:Bloom 很吃性能,场景模型多的时候不能全场景开启;一定要用分层渲染,单独渲染需要发光的物体。

On the way 284
上一篇: [设计模式]DAO的实现方式探讨_Part II
下一篇: [Design Pattern] Template Method Pattern
Fitzwilliam
博客等级 码龄21年 10粉丝 92原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值