表单元素操作,button,点击下载按钮实现-长知识

禁用按钮

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<button id="btn">Click Me</button>
<script>
    var obtn = document.getElementById('btn');

    obtn.onclick = function () {
//        this.disabled = true;
//        this.setAttribute('disabled', 'true');
    }

</script>
</body>
</html>

小技巧:

 location.href 实现点击下载功能

http://www.cnblogs.com/zichi/p/4929930.html

45个JavaScript小技巧

http://www.cnblogs.com/zichi/p/5094902.html

【优雅代码】深入浅出 妙用Javascript中apply、call、bind
http://www.cnblogs.com/coco1s/p/4833199.html

常用的表单事件及用法--select option


记录一下常用的表单事件,因为工作中常用到所以特别记录一下。有jq写法和原生js写法

1.这是select的option的事件,jq写法

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<script src="../jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {

    $('#sel').change(function () {
        
        console.log( $(this).val() );
    })
    
})

</script>
</head>
<body>
    <select name="" id="sel">
        <option value="aaa" selected="selected">111</option>
        <option value="bbb">222</option>
        <option value="ccc">333</option>
    </select>
    <p>
        jQuery中获得选中select值
        var checkText=$("#select_id").find("option:selected").text();  //获取Select选择的Text
        var checkValue=$("#select_id").val();  //获取Select选择的Value
        var checkIndex=$("#select_id ").get(0).selectedIndex;  //获取Select选择的索引值
        var maxIndex=$("#select_id option:last").attr("index");  //获取Select最大的索引值
    </p>
    <p>来源:http://www.cnblogs.com/mitang/p/3687353.html</p>
</body>
</html>

HTML 下拉框 select option 详解
http://blog.csdn.net/sanyuesan0000/article/details/8593863

原文地址:https://www.cnblogs.com/masita/p/5039134.html