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

PHP中文网
Release: 2017-06-07 13:26:01
Original
1699 people have browsed it
产品姐姐想法多,点击input项才能聚焦进行操作,点击外部不能有反应
Copy after login

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

<label for="label-input"><input type="text" class="" id="label-input"><br><button>buttonbutton>label>
Copy after login

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

<link rel="stylesheet" type="text/css" href="bootstrap.min.css?1.2.45">
Copy after login

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

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

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~

$(&#39;label&#39;).click(function() {return false;
});

$(&#39;#label-input&#39;).click(function(e) {var elem = e.target;
    console.log(elem.tagName);
})
Copy after login

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!