jquery代码导致IE崩溃

磐创 AI
博客专家认证
2012-12-28 01:41:29

<html>

<head>
<link rel="stylesheet" type="text/css" href="css/register.css" />
<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
<script type="text/javascript" src="js/register.js"></script>

<!--

-->
</head>

<body>
<div id="box">
<div id="logo">
<img src="image/logo.gif" width="128" height="128">
<p></p>
</div>
<div class="form">
<form action="register.php" method="get">
<!--自己写的注册框
<input type="text" class="input" value="your name" />
-->
<div>
<div><p><input class="input" type="text" name="username" value="用户名"/></p></div>
<div><p><input class="input" type="password" name="password" value="密码"/></p></div>
<div><p><input class="input" type="password" name="password" value="密码"/></p></div>
<div><p><input class="input" type="text" name="email" value="邮箱"/></p></div>
<div><input type="submit" value="注册" /></div>
</div>
</form>
</div>
</div>

</body>
</html>


$(document).ready(function() {
//each遍历文本框
$(".input").each(function() {
//保存当前文本框的值
var vdefault = this.value;
$(this).focus(function() {
//获得焦点时,如果值为默认值,则设置为空
if (this.value == vdefault) {
this.value = "";
}
});
$(this).blur(function() {
//失去焦点时,如果值为空,则设置为默认值
if (this.value == "") {
this.value = vdefault;
}
});
});
});
...全文
184 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
爱若如梦 2012-12-28
  • 打赏
  • 举报
回复
不知道你的浏览器以及jquery版本,我用ie9,切换到ie7、8都没有问题,使用的jquery为http://code.jquery.com/jquery-1.8.0.js这个js
磐创 AI 2012-12-28
  • 打赏
  • 举报
回复
后面那段JS,是register.js里面的内容已经有标签了,我描述不清楚。
爱若如梦 2012-12-28
  • 打赏
  • 举报
回复
引用 楼主 fendouaini 的回复:
<html> <head> <link rel="stylesheet" type="text/css" href="css/register.css" /> <script type="text/javascript" src="js/jquery-1.8.0.js"></script> <script type="text/javascript" src="js/register.……
...加上js类型标签即可 <script type="text/javascript"></script>

<html>

<head>
<link rel="stylesheet" type="text/css" href="css/register.css" />
<script type="text/javascript" src="jquery.js"></script>
<!--script type="text/javascript" src="js/register.js"></script -->

<!--

-->
</head>

<body>
<div id="box">
<div id="logo">
<img src="image/logo.gif" width="128" height="128">
<p></p>
</div>
<div class="form">
<form action="register.php" method="get">
<!--自己写的注册框
<input type="text" class="input" value="your name" />
-->
<div>
  <div><p><input class="input" type="text" name="username"  value="用户名"/></p></div>
  <div><p><input class="input" type="password" name="password" value="密码"/></p></div>
  <div><p><input class="input" type="password" name="password" value="密码"/></p></div>
  <div><p><input class="input" type="text" name="email" value="邮箱"/></p></div>
  <div><input type="submit" value="注册" /></div>
</div>
</form>
</div>
</div>

</body>
<script type="text/javascript">
$(document).ready(function() {
    //each遍历文本框
    $(".input").each(function() {
        //保存当前文本框的值
        var vdefault = this.value;
        $(this).focus(function() {
            //获得焦点时,如果值为默认值,则设置为空
            if (this.value == vdefault) {
                this.value = "";
            }
        });
        $(this).blur(function() {
            //失去焦点时,如果值为空,则设置为默认值
            if (this.value == "") {
                this.value = vdefault;
            }
        });
    });
});
</script>
</html>



87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧