类型转化:

parseInt() 转整数
parseFloat() 转小数
Number() 转数字
toString() 转字符串

 JSON 转换:

//j son 对象数组转j son 字符串
var jsonstr=JSON.stringify(obj)
//j son字符串转对象
JSON.parse(str);

RequireJS 使用:

 

 

遍历radio ,为其赋初始值


<input type="radio" class="approve_state" name="approve_state" id="sc" value="1">设为【仅作者可见】
<input type="radio" class="approve_state" name="approve_state" id="sc" value="2">设为【进主页可见】
<input type="radio" class="approve_state"name="approve_state" id="sc" value="3">设为【精选素材】
<input type="radio" class="approve_state" name="approve_state" id="sc" value="4">设为【精选且置顶】

   
$(function() { var radio =$('.approve_state'); var approve_state= '${dataPager.approve_state}'; //遍历radio 为radio 赋予目前状态初始值 if(approve_state !=0){ for(var i=0; i
<radio.length;i++){ if(radio[i].value == approve_state){ radio[i].checked = true; break; } } } })

2. 判断checkbox 是否选中

 if ($('#checkbox1').attr('checked'))

3.获取checkox 选中的value值

 $("input[name='approve_state']:checked").val();

4.js 图片播放器插件,很强大 下载链接:https://github.com/fengyuanchen/viewerjs

需要引入:
<link rel="stylesheet" href="static/css/viewer.min.css" />
<script type="text/javascript" src="static/js/viewer.min.js"></script>

html:
<ul id="imgs">
    <li><img src="img/tibet-1.jpg" alt="图片1"></li>
    <li><img src="img/tibet-2.jpg" alt="图片2"></li>
    <li><img src="img/tibet-3.jpg" alt="图片3"></li>
    <li><img src="img/tibet-4.jpg" alt="图片4"></li>
    <li><img src="img/tibet-5.jpg" alt="图片5"></li>
    <li><img src="img/tibet-6.jpg" alt="图片6"></li>
</ul>

js:
    var viewer = new Viewer(document.getElementById('imgs'), {
            minZoomRatio :0.5//定义配置

        });


具体配置:https://blog.csdn.net/aoshilang2249/article/details/51824256

 5.js中将el 表达式json 字符串转换为json object

 var layout = jQuery.parseJSON( '${layout}');

6.js 遍历json 对象,非json 数组

    for(var key in layout){
        //你的操作,key 为json key ,layout[key] 为value
            initlayout(key,layout[key]);
          }    

7.jquery 属性赋值

$("#key").attr("src","www.baidu.com");

8.jquery css 赋值

$("#key").css("background-repeat","inherit");

9.jquery input value 赋值

 $("#key").val(value);

 10,传递变量事件中(role 为变量)

onclick=deleteManager(this,'"+role+"')
 onBlur="getManagerCount(\''+role+'\')"

11.获取checkbox 值:

 var arr=[];
            $(".mark input[type='checkbox']:checked").each(function(index,item){
                arr.push($(this).val());
            });

 

posted on 2018-10-25 15:56  iscys  阅读(129)  评论(0编辑  收藏  举报