Home > Web Front-end > JS Tutorial > Principle analysis of obtaining data in div under js_javascript skills

Principle analysis of obtaining data in div under js_javascript skills

WBOY
Release: 2016-05-16 18:30:19
Original
898 people have browsed it

Regarding the knowledge learned from it:
document.getelementbyid("ddhdh").innerHTML can get all the data in the div, including tags. . . But just using
document.getelementbyid("ddhdh").innerTEXT in IE and OPERA can get the text data in the div, but not the tag. . . But just use
document.getElementById(“text”).textContent in IE and OPERA to get data in Firefox
Principle analysis of obtaining data in div under js_javascript skills
The above tag is based on the two browsers these days. For kernel browsers, these methods are incompatible.

The following is the solution

JS compatible with Firefox IE to get the content of the div
if(navigator.appName.indexOf("Explorer") > -1)

var text = document.getElementById(“text”).innerText;
else
var text = document.getElementById(“text”).textContent;

is used to get The name of the browser, the first sentence means that the name of the obtained browser contains Explorer.

Involves indexof usage

strObj.indexOf(subString[, startIndex])

Parameters
strObj

Required. String object or literal.

subString

Required. The substring to find in the String object.

starIndex

Optional. This integer value indicates the index within the String object at which to begin the search. If omitted, the search is from the beginning of the string.

The indexOf method returns an integer value indicating the starting position of the substring within the String object. If the substring is not found, -1 is returned.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template