为什么它在jsfidde而不是在我的浏览器上工作? [英] Why does it work in jsfidde but not on my browser?

查看:99
本文介绍了为什么它在jsfidde而不是在我的浏览器上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看此jsfiddle:

Please check out this jsfiddle:

http: //jsfiddle.net/xNEZH/2/

它在我的jsfiddle中正常工作

It works fine in my jsfiddle

[在输入文本时输入文本框]

[BOX APPEARS WHEN TEXT IS INPUTTED IN INPUT]

但不能在我的浏览器上使用但是我使用的是safari,firefox和chrome的最新版本。

but doesn't work on my browsers BUT I am using the latest versions of safari, firefox and chrome.

有什么问题?

HTML / JAVASCRIPT CODE:

HTML / JAVASCRIPT CODE:

<html>
<head>

<script type="text/javascript" src="jquery-1.7.js"></script>
<script>
$(document).ready(function () {
(function watchInputForChanges(){
    var hasInput = $('.input1').val() != "";
    $('.box')[hasInput ? 'show' : 'hide']();
    setTimeout(watchInputForChanges, 100);
})();
});
</script>

<link href="cloud.css" rel="stylesheet" type="text/css" />

</head>
<body>

<div class="center1">
<form>
<input type="text" class="input1" autofocus="focus"  />
</form>
</div>

<br><br>

<div class="center1">
<div class="box">f</div>
</div>


</body>
</html>


推荐答案

我相信你需要添加: p>

I believe that you need to add this:

$(document).ready(function () {
    //function name does not exist outside this scope
    (function watchInputForChanges(){
        var hasInput = $('.input1').val() != "";
        $('.box')[hasInput ? 'show' : 'hide']();
        setTimeout(watchInputForChanges, 100);
    })();
});



Drav Sloan 指出缺少jQuery include以及


Drav Sloan pointed out that you are missing the jQuery include as well

这篇关于为什么它在jsfidde而不是在我的浏览器上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆