js常用命令

1、清空select的option内容,真的下拉空动态更新需求

$("#search").find("option").remove(); 

2、在某id下新增内容

$("#brand_name").append(viewStr);

3、某标签赋值取值

$("#brand_vender").val("赋值");
$("#brand_vender").val();
$('#brand_vender').val().trim(); //去掉空格

 4、jquery热键冲突处理:eg:$

Uncaught TypeError: $ is not a function
<script type="text/javascript">
       var $jq = jQuery.noConflict(true);
</script>

5、js监听事件

$(".gj_sign").click(function f() {
 
     //监听事件操作 
   
})

6、js获取id对象进行操作:

$("#id")

7、js获取class进行操作

$(".class")

8、获取某id下的所有子标签

第一种:$.all('img',$.all('#plantInfo')[0]);

第二种: $(".img-list li img")
得到的是数组

9、遍历数组

第一种:imgs.forEach(function(v,i){
        urls.push(v.src);
})

第二种:for(var i = 0; i < $(".img-list li img").size(); i++){
var src = $(".img-list li img")[i].src;
}

9、移动端图片展示 Demo

https://github.com/yanghuiLu/previewImage-mobile

https://github.com/dimsemenov/PhotoSwipe

10、对子组建的获取

$(".img-list li img")
原文地址:https://www.cnblogs.com/ljangle/p/11764582.html