文本框的内容不能输出 var t = $("#txtest").html();$("div").html("您的姓名为:"+t);

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>表单中文本框的focus和blur事件</title>
        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>
        <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    
    <body>
        <h3>表单中文本框的focus和blur事件</h3>
        <input id="txtest" type="text" value="" />
        <div></div>
        
        <script type="text/javascript">
            $(function () {
                $("input")
                .bind("focus", function () {
                    var t = $("#txtest").html();
                    $("div").html("您的姓名为:"+t);
                })
                $("input").bind("focus", function () {
                    if ($(this).val().length == 0)
                        $("div").html("你的名称不能为空!");
                })
            });
        </script>
    </body>
</html>

星束海
浏览 1477回答 1
1回答

Perona

获取表单的值用val()。下面知道用val()。怎么上面反而忘了。把var t = $("#txtest").html();改成var t = $("#txtest").val();即可。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery