The label is used for the input items in the form, and the Bootstrap library is referenced at the same time, resulting in an increase in the input click effect area. labelbootstrap

Source: Internet
Author: User

The label is used for the input items in the form, and the Bootstrap library is referenced at the same time, resulting in an increase in the input click effect area. labelbootstrap

The product elder sister has many ideas. Only by clicking the input item can she focus on the operations. When clicking the external button, no response can be made.

Okay... Go straight to the subject

To make tags more semantic, we often use label for encapsulation in form items.

<label for="label-input">    <input type="text" class="" id="label-input"><br>    <button>button</button></label>

In the development of the mobile platform page, to make the vertex area of the form item become larger and better, the label can provide corresponding convenience.

But sometimes, we only need label labels, but do not want to increase the area without reason. The introduction of Bootstrap automatically increases the accessible area.

As shown in, you only need to click the input item to produce results. However, clicking other empty areas in the label triggers the event (note that clicking the button does not trigger the event)

Only the Bootstrap Style Library is introduced.

<link rel="stylesheet" type="text/css" href="bootstrap.min.css">

 

To solve this problem, try to determine the event-triggered object. However, the INPUT tag is always invalid. It is not scientific.

$('#label-input').click(function(e) {    var elem = e.target;    console.log(elem.tagName);    if (elem.tagName !== 'INPUT') {        return false;    }})

 

What can I do?

I thought of another method. I made another listener and clicked label, and then directly returned false., OK ~

$('label').click(function() {    return false;});$('#label-input').click(function(e) {    var elem = e.target;    console.log(elem.tagName);})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.