Home >Web Front-end >JS Tutorial >Sample code for obtaining and modifying label value with JS and Jquery_javascript skills

Sample code for obtaining and modifying label value with JS and Jquery_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:03:451153browse

Get the value:

The label tag is used in JS and Jquery and cannot be used to get its value like other tags:

Copy code The code is as follows:

var label=document.getElementById("id");
var value=label.value;
var value=$("#id ").val();

can be like this:

JS:
Copy code The code is as follows:

var label=document.getElementById("id");
var value=label.innerText;

Jquery:
Copy code The code is as follows:

var value=$("#id").html() ;

Assignment:

Unlike Java, JS and Jquery cannot assign value like this:
Copy code The code is as follows:

var label=document.getElementById("id");
var value=label.innerText;
value="XXXXXX";

Copy code The code is as follows:

var value=$("#id ").html();
value="XXXXXX";

can be assigned like this:
Copy code The code is as follows:

var label=document.getElementById("id");
label.innerText="XXXXXX";
$("#id") .html("XXXXX");
Statement:
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