HTML DOM model: Before the w3c dom model (specification) appeared, each browser supported some DOM operations
Select object
Attributes: selectedIndex: indicates the subscript of the option currently selected by the user (from 0 Start) length: Get or set the length of the option options: The value is an array, each array element is an option object, representing all the options of the drop-down list Option object
Attributes: text: Description of the option value: The value of the option selected: When the value is true, it means that this option is selected by the user and the Option object can be created as follows
var obj = new Option(text, value);
<html> <head> <script src="myjs.js"></script> <script> function f1(){ //alert($('s1').selectedIndex); //alert($('s1').length); var arr = $('s1').options; for(i=0;i<arr.length;i++){ alert(arr[i].text +' '+ arr[i].value); } } function f2(){ var op = new Option('武汉','wh'); $('s1').options[$('s1').options.length] = op; } </script> </head> <body> <select id="s1" style="width:120px;" name="s1"> <option value="bj">北京</option> <option value="sh">上海</option> <option value="xa">西安</option> <option value="sz">深圳</option> <option value="tj">天津</option> </select> <input type="button" value="点我吧" onclick="f2();"/> </body> </html>
Cascading drop-down list
<html> <head> <script src="myjs.js"></script> <script> var arr = new Array(); arr[0] = [new Option('--方向--','-1')]; arr[1] = [new Option('商务英语','en1'), new Option('专业英语','en2')]; arr[2] = [new Option('计算机软件','comp1'), new Option('计算机网络','comp2'), new Option('计算机应用','comp3')]; //数组的创建放在外面执行效率更高 function change(index){ $('s2').length = 0; for(i=0;i<arr[index].length;i++){ $('s2').options[i] = arr[index][i]; } } </script> </head> <body> <select id="s1" style="width:120px;" onchange="change(this.selectedIndex);"> <!-- this表示绑定该事件的节点,在这里表示<select>节点--> <option value="-1">--专业--</option> <option value="english">英语</option> <option value="computer">计算机</option> </select> <select id="s2" style="width:120px;"> <option value="-1">--方向--</option> </select> </body> </html>
Table object is equivalent to
<html> <head> <script src="myjs.js"></script> <script> //html dom模型做 function addRow1(){ var tr = $('t1').insertRow($('t1').rows.length); var td1 = tr.insertCell(tr.cells.length); var td2 = tr.insertCell(tr.cells.length); td1.innerHTML = $('name').value; td2.innerHTML = $('salary').value; //tr.style.backgroundColor = 'red'; //两种样式1 //tr.className = 'selected'; //两种样式2 $('t1').rows[1].cells[1].style.backgroundColor = 'red';//把某一格加亮 } //采用w3c dom模型做 function addRow2(){ var tr1 = document.createElement('tr'); var td1 = document.createElement('td'); var td2 = document.createElement('td'); td1.innerHTML = $('name').value; td2.innerHTML = $('salary').value; tr1.appendChild(td1); tr1.appendChild(td2); $('t1').appendChild(tr1); } </script> <style> .selected{ background-color:red; } </style> </head> <body> <table id="t1" border="1" cellpadding="0" cellspacing="0" width="60%"> <tr><td>姓名</td><td>工资</td></tr> <tr><td>zs</td><td>2000</td></tr> <tr><td>ls</td><td>3000</td></tr> <tr><td>wu</td><td>4000</td></tr> </table><br/> 姓名:<input type="text" name="name" id="name"/> 工资:<input type="text" name="salary" id="salary"/> <input type="button" value="添加" onclick="addRow2();"/> </body> </html> The above is the content of Xiaoqiang’s HTML5 mobile development road (31) - JavaScript review 6. For more related content, please pay attention to the PHP Chinese website (www.php.cn)! |

The usage methods of HTML tags and attributes include: 1. Basic usage: Use tags such as and, and add necessary information through attributes such as src and href. 2. Advanced usage: Use data-* custom attributes to achieve complex interactions. 3. Avoid common mistakes: Make sure the property values are surrounded by quotes. 4. Performance optimization: Keep it simple, use standard attributes and CSS class names to ensure that the image has alt attributes. Mastering these will improve web development skills.

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
