jQuery可以在jsFiddle中使用,但不能在我的计算机上使用

编程入门 行业动态 更新时间:2024-10-24 17:29:58
本文介绍了jQuery可以在jsFiddle中使用,但不能在我的计算机上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是jQuery的新手,整日忙于试图确定为什么该脚本在jsFiddle中运行而不是在我的计算机上运行的想法.我没有服务器设置,我只是从桌面在浏览器中启动html.

I'm new to jQuery and have been scratching my head all day trying to determine why this script runs in jsFiddle but not on my computer. I do not have a server setup, I am merely launching the html in my browser from the desktop.

代码在这里可以正常使用: jsfiddle/9Dubr/164/.但是,当我创建以下html文件时:

The code works fine here: jsfiddle/9Dubr/164/. However when I create the following html file:

<html> <head> <title>this better work</title> <script src="jquery-latest.js"></script> <script type="text/javascript"> $('#submit').click(function(){ $('#myfrom').fadeOut("slow", function(){ var dot = $("<div id='foo'>Goodmorning Mr. Patti<br/><br/>Thank you.</div>".hide(); $(this).replaceWith(dot); $('#foo').fadeIn("slow"); }); }); </script> <style type="text/css"> #container{ width:342px; height:170px; padding:10px; background-color:grey; } #myform{ width:322px; height:100px; color:#6F6F6F; padding: 0px; outline:none; background-color:white; } #foo{ width:322px; height:100px; color:#6F6F6F; padding: 0px; outline:none; background-color:white; } #submit{ color:#6F6F6F; padding: 10px 2px 0px 0px; margin: 0px 0px 0px 0px; outline:none; } </style> </head> <body> <div id="container"> <div id="myform"> <p> blah blah blah blah blah </p> <input id="submit" value="send" type="submit"/> </div> </div> </body> </html>

当我单击提交按钮时,没有任何结果.请帮忙,我已经花了6个小时了.

I get no results when I click the submit button. Please help, I've spent 6 hours on this.

谢谢

推荐答案

您必须在DOM上执行代码.将代码包装在$(function(){ });中此外,您还缺少).

You have to execute the code on DOM ready. Wrap your code in $(function(){ }); Also, you're missing a ).

$(function () { $('#submit').click(function () { $('#myfrom').fadeOut("slow", function () { var dot = $("<div id='foo'>Goodmorning Mr. Patti<br/><br/>Thank you.</div>").hide(); $(this).replaceWith(dot); $('#foo').fadeIn("slow"); }); }); });

<!DOCTYPE html> <html> <head> <title>This better work</title> <script src="ajax.googleapis/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(function () { $('#submit').click(function () { $('#myfrom').fadeOut("slow", function () { var dot = $("<div id='foo'>Goodmorning Mr. Patti<br/><br/>Thank you.</div>").hide(); $(this).replaceWith(dot); $('#foo').fadeIn("slow"); }); }); }); </script> </head> <body> <div id="container"> <form id="myform"> <p> blah blah blah blah blah </p> <input id="submit" value="send" type="submit"/> </form> </div> </body> </html>

更多推荐

jQuery可以在jsFiddle中使用,但不能在我的计算机上使用

本文发布于:2023-11-11 18:01:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能在   但不   机上   jQuery   jsFiddle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!