Home  >  Article  >  Web Front-end  >  HTML passes parameters to js through events detailed explanation and examples

HTML passes parameters to js through events detailed explanation and examples

高洛峰
高洛峰Original
2017-03-28 11:40:341448browse

Target processingFunction is selectAttr(test)

1. Directly pass the given parameters such as:

onclick="selectAttr('1');
onclick="selectAttr('a');

2. Pass a certain attribute Value

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

3. Pass this object

onclick="selectAttr(this);

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");

code is a custom attribute.

jqery method to obtain:

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

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!

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