[Jquery]自动选取焦点和one绑定事件

来源:互联网 发布:update数据库 编辑:程序博客网 时间:2024/06/05 15:24

1.one绑定时间

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>其他事件one</title>    <script type="text/javascript"             src="Jscript/jquery-1.4.2-vsdoc.js">    </script>    <script type="text/javascript"             src="Jscript/jquery-1.4.2.js">    </script>    <style type="text/css">           .btn {border:#666 1px solid;padding:2px;width:160px;           filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffff, EndColorStr=#ECE9D8);}    </style>    <script type="text/javascript">        $(function() {            function btn_Click() { //自定义事件                $("div").append("010-12345678");            }            $("input").one("click", btn_Click); //绑定自定义事件        })    </script></head><body>    <input id="Button1" type="button" value="点击查看联系方式" class="btn" />    <div></div></body></html>


2.自动选取焦点

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>其他事件trigger</title>    <script type="text/javascript"             src="Jscript/jquery-1.4.2-vsdoc.js">    </script>    <script type="text/javascript"             src="Jscript/jquery-1.4.2.js">    </script>    <style type="text/css">            body{font-size:13px}            .txt{border:#666 1px solid;padding:3px}    </style>    <script type="text/javascript">        $(function() {            var oTxt = $("#Text1"); //获取文本框            oTxt.trigger("select"); //自动选中文本框            oTxt.bind("btn_Click", function() {//编写文本框自定义事件                var txt = $(this).val(); //获取自身内容                $("#divTip").html(txt); //显示在页面中            })            oTxt.trigger("btn_Click"); //自动触发自定义事件        })    </script></head><body>    姓名:<input id="Text1" type="text" class="txt"  value="octopus" />    <br><br>    电话:<input id="Text2" type="text" class="txt" value=""/><br><br>    地址:<input id="Text3" type="text" class="txt" value=""/><br><br>          <div id="divTip" style="padding-top:5px"></div></body></html> 



0 0