`
烈火
  • 浏览: 8173 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

jquery 编程注意问题

阅读更多
1.判断我的选择是否包含元素?

// 不要这样做!

if ( $( "div.foo" ) ) {

}

// 请使用length属性

if ( $( "div.foo" ).length ) {

}

2.需要重复调用同一个选择时,请缓存你的选择:

var divs = $( "div" );

3.获取dom对象

$( "#foo" )[ 0 ];

4.select相关

$( "#myselect" ).val();

$( "#myselect option:selected" ).text();

5.checkbox/radio相关

$( "#x" ).prop( "checked", true );

$( "#x" ).prop( "checked", false );

6.Disabled

$( "#x" ).prop( "disabled", true );

$( "#x" ).prop( "disabled", false );

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics