当Bootstrap切换按钮类处于活动状态时,jQuery会执行某些操作 [英] jQuery do something when Bootstrap toggle button class is active

查看:77
本文介绍了当Bootstrap切换按钮类处于活动状态时,jQuery会执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 JavaScript/jQuery 的新手,因此可以在这里提供一些帮助.我有以下形式的输入:

I'm new to JavaScript/jQuery so could do with some assistance here. I have the following inputs in a form:

<div class="form-group">
    <button type="button" class="btn btn-default navbar-btn" data-toggle="button tooltip"
    data-placement="right" title="Use your exact location" name="geoloc" id="geoloc">
        <li class="icon-screenshot"></li>
    </button>
</div>
<div class="form-group">
    <input type="text" class="form-control" placeholder="Address" name="address"
    id="address">
    <input name="lat" type="hidden" value="">
    <input name="lng" type="hidden" value="">
</div>

如果用户单击geoloc切换按钮(这意味着表单将使用其确切位置),则我试图禁用地址输入文本框,因为该文本框变得多余.

I'm trying to disable the address input text box if the user clicks the geoloc toggle button (which means the form will use their exact location) as the text box becomes redundant.

当geoloc输入类处于活动状态时,如何让浏览器将"disabled"属性应用于地址输入,而当geoloc按钮没有处于活动状态时,如何启用地址输入?

How do I get the browser to apply the 'disabled' attribute to the address input when the geoloc input class is active, and enable the address input when the geoloc button doesn't have the active class?

推荐答案

切换地址字段的Disabled属性的基本方法:

A basic approach to toggling your address field's disabled property:

$('#geoloc').click(function (e) {
        var $address = $('#address');
        $address.prop("disabled", !$address.is(':disabled'));
});

这篇关于当Bootstrap切换按钮类处于活动状态时,jQuery会执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆