第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

jQuery復(fù)選框更改并單擊事件

jQuery復(fù)選框更改并單擊事件

有只小跳蛙 2019-07-25 18:53:05
jQuery復(fù)選框更改并單擊事件$(document).ready(function() {   //set initial state.   $('#textbox1').val($(this).is(':checked'));   $('#checkbox1').change(function() {     $('#textbox1').val($(this).is(':checked'));   });   $('#checkbox1').click(function() {     if (!$(this).is(':checked')) {       return confirm("Are you sure?");     }   });});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><input type="checkbox" id="checkbox1"/><br /><input type="text" id="textbox1"/>
查看完整描述

3 回答

?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊

好吧,我沒有看到與我匹配的答案,所以我會發(fā)布這個。在JSFiddle中測試并執(zhí)行您要求的操作。當單擊與復(fù)選框關(guān)聯(lián)的標簽時,此方法具有觸發(fā)的額外好處。

原答案:

$(document).ready(function() {
    //set initial state.
    $('#textbox1').val($(this).is(':checked'));

    $('#checkbox1').change(function() {
        if($(this).is(":checked")) {
            var returnVal = confirm("Are you sure?");
            $(this).attr("checked", returnVal);
        }
        $('#textbox1').val($(this).is(':checked'));        
    });});

更新答案:

$(document).ready(function() {
    //set initial state.
    $('#textbox1').val(this.checked);

    $('#checkbox1').change(function() {
        if(this.checked) {
            var returnVal = confirm("Are you sure?");
            $(this).prop("checked", returnVal);
        }
        $('#textbox1').val(this.checked);        
    });});


查看完整回答
反對 回復(fù) 2019-07-25
?
子衿沉夜

TA貢獻1828條經(jīng)驗 獲得超3個贊

演示

使用 mousedown

$('#checkbox1').mousedown(function() {
    if (!$(this).is(':checked')) {
        this.checked = confirm("Are you sure?");
        $(this).trigger("change");
    }});


查看完整回答
反對 回復(fù) 2019-07-25
  • 3 回答
  • 0 關(guān)注
  • 689 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號