suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript – Zeit, die ausgelöst wird, wenn das Kontrollkästchen aktiviert und deaktiviert wird

$(".checkboxs_yy").click(function(){

       if($(this).attr("checked")==true){
           console.log("选中");
       }else{
           console.log("未选中");
       } 
    });

.checkboxs_yy ist ein Kontrollkästchen, das eine Zeit auslöst, wenn es aktiviert ist, und ein anderes Ereignis auslöst, wenn es nicht aktiviert ist. Wie soll ich es ändern?

PHPzPHPz2864 Tage vor847

Antworte allen(4)Ich werde antworten

  • 大家讲道理

    大家讲道理2017-05-18 11:03:31

    $(".checkboxs_yy").click(function(){
        if($(this).is(":checked")){
            console.log("选中");
        }else{
            console.log("未选中");
        }
    });

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-05-18 11:03:31

    $(this).is(":checked")

    Antwort
    0
  • 为情所困

    为情所困2017-05-18 11:03:31

    使用这个$(this).prop('checked')而不用$(this).attr('checked')用来获取动态可变的属性。

    Antwort
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-18 11:03:31

    attr()在checkbox下不适合用来做是否被选中的判断,可以用.is(":checked")或.prop("checked", true)来做是否被选中的判断。
    在jQuery API有相关说明,1.6+的jQuery要用prop,尤其是 checkBox 的 checked 的属性的判断,
    同时 .is(":checked") 适合所有版本

    Antwort
    0
  • StornierenAntwort