Home  >  Article  >  Web Front-end  >  The form input item uses label and references the Bootstrap library, which causes the input click effect area to increase.

The form input item uses label and references the Bootstrap library, which causes the input click effect area to increase.

PHP中文网
PHP中文网Original
2017-06-07 13:26:011622browse
产品姐姐想法多,点击input项才能聚焦进行操作,点击外部不能有反应

In order to make labels more semantic, we often use labels to wrap form items

In the development of mobile platform pages, in order to make the clickable area of ​​form items larger For better operation, label can provide corresponding convenience.

But sometimes, we just need the label, but we don’t want the clickable area to increase for no reason. The introduction of Bootstrap automatically increases the clickable area

As shown in the picture above, it is only expected that clicking on the input item will have an effect, but clicking on other empty areas within the label label will trigger it (note that clicking on the button will not trigger)

just introduced Bootstrap’s style library

In order to solve it, try to determine the object triggered by the event . However, it is invalid, it is always the INPUT label, it is unscientific

$('#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 a way, and then set up a monitor to click the label, and then directly return false

, OK~

$('label').click(function() {return false;
});

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

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