Stefan Brinkmann的答案很好,但对于初学者来说还不完整(省略了变量分配)。只是澄清一下:// this structure is called a ternary operatorvar cbAns = ( $("#ans").is(':checked') ) ? 1 : 0;它是这样的: var myVar = ( if test goes here ) ? 'ans if yes' : 'ans if no' ;例:var myMath = ( 1 > 2 ) ? 'yes' : 'no' ;alert( myMath );警报“否”如果这有帮助,请支持Stefan Brinkmann的答案。