Home  >  Article  >  WeChat Applet  >  How to obtain the custom attributes of the mini program

How to obtain the custom attributes of the mini program

angryTom
angryTomOriginal
2020-03-19 17:00:293038browse

How to obtain the custom attributes of the mini program

How to obtain the custom attributes of the mini program

The identifier of the custom attribute: data-attrName, where the following "attrName" is optional Naming, the prefix "data-" is required.

The specific methods for obtaining custom attributes of mini programs are as follows:

1. Add custom attributes

<button data-info="自定义数据" bindtap="testClick">自定义属性测试</button>

2. Get custom attributes Attribute

testClick(event){
    const dataInfo = event.currentTarget.dataset.info;
    console.log(dataInfo)
}

Program explanation:

The click event testClick is bound to the button; after clicking, e.currentTarget gets the attribute of [the object where the bintap is located]; the custom attribute is stored In the dataset, you can use the event.currentTarget.dataset.property name to get the custom property.

PHP Chinese website, a large number of 小program development tutorials are welcome to learn!

The above is the detailed content of How to obtain the custom attributes of the mini program. 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