HTML passes parameters to js through events detailed explanation and examples

高洛峰
Release: 2017-03-28 11:40:34
Original
1448 people have browsed it

Target processingFunction is selectAttr(test)

1. Directly pass the given parameters such as:

onclick="selectAttr('1');
onclick="selectAttr('a');
Copy after login

2. Pass a certain attribute Value

<input type="text" id="nameId" name="typeName">
onclick="selectAttr(typeName.value);
onclick="selectAttr(nameId.value);
Copy after login

3. Pass this object

onclick="selectAttr(this);
Copy after login

Get the corresponding option value through this object: this.value or this.name;

If yes Custom attributes can be obtained in the following ways:

document:

var divs=document.getElementById("typeName1");
 var x=divs.getAttribute("code");
Copy after login

code is a custom attribute.

jqery method to obtain:

$("#typeName").attr("value"); 
var typeName=$("#sel").find("option:selected").attr("code");
Copy after login

The above is the detailed content of HTML passes parameters to js through events detailed explanation and examples. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!