如果使用jQuery有2或3或20个语句
$(function() { ... })
Run Code Online (Sandbox Code Playgroud)
要添加要在DOM准备好时执行的函数,所有这些函数是并行运行还是按顺序运行?
如何检查所有输入框以查看文档加载时是否有值?
$(document).ready(function(){
var inputVal=$("input").val().trim();
if(inputVal!=''){
}
})
Run Code Online (Sandbox Code Playgroud)
我想对任何有值的输入框执行操作.
我是jquery的新手,看了一些教程,但我甚至无法自己开始.看起来$(document).ready下的东西永远不会被调用.这是我的HTML的前几行:
<html>
<head>
<title>foobar</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type=\"text/javascript\">
$(document).ready(function(){
alert("READY!");
$("*").click( function() {
alert("CLICKED!");
});
}); </script>
...(some other scripts)
</head>...
Run Code Online (Sandbox Code Playgroud)
我觉得这是最基本的,但是当我加载或点击页面中的某些内容时,我没有收到任何警报.从外部文件加载jquery也不起作用.我正在使用Firefox 9.我不知道从哪里开始,我似乎无法在网上找到解决我问题的任何内容.有没有人知道造成这种情况可能有什么问题?谢谢!
当我访问www.reuters.com时,我无法弄清楚为什么这至少不会提醒我一次.我错过了什么吗?
// ==UserScript==
// @name test3
// @namespace test3
// @version 1
// ==/UserScript==
$(document).ready(function () {
var actualHost = window.location.toString();
var intendedHost = "www.reuters.com";
alert("Debug 1 - " + actualHost);
if (actualHost == intendedHost) {
alert("Debug 2 - " + actualHost);
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢.
N00b在这里.如果这是一个糟糕的问题,请提前道歉.
实际上,这两个jQuery声明之间有什么区别?
$(document).ready(function(){
alert("I'm so loaded 1.");
});
Run Code Online (Sandbox Code Playgroud)
和
$('document').ready(function(){
alert("I'm so loaded 2.");
});
Run Code Online (Sandbox Code Playgroud)
在相关的说明中,为什么这样做......
$(document).on('ready',function() {
alert("I'm so loaded 3.");
});
Run Code Online (Sandbox Code Playgroud)
......但这不是吗?
$('document').on('ready',function() {
alert("I'm so loaded 4.");
});
Run Code Online (Sandbox Code Playgroud) 我认为$(document).ready(...)中的脚本总是在加载DOM后执行.因此,如果一个$(document.ready(...)进入头部或正文中就没关系.但是,下面的代码不会像我想要的那样在屏幕上生成"苹果".如果我找到页面底部的giveApples()函数,它可以工作.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(giveApples());
function giveApples() {
$("#appleTree").html("apples");
}
</script>
</head>
<body>
<div id="appleTree"></div>
</body>
<script>
//$(document).ready(giveApples());
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
任何人都可以请更正我对DOM,页面加载,脚本标记位置,(文档).ready()或其他任何导致此问题的误解吗?我还是网络编程的新手.
我有一个jQuery函数,通常在Volusion页面上工作,由于某种原因现在它不起作用.location.pathname.indexOf定位具有该URL的所有页面(该站点使用GET变量在SearchResults.asp页面上执行搜索).我已经将引用从单打改为双打,我似乎无法找出其他任何东西来测试它.有没有人在这段代码中看到任何语法错误?不应该有任何冲突,因为它只运行jQuery(没有其他像MooTools).我试图在document.ready之后做一个'Test'警报,但屏幕上没有任何反应.谢谢!
<script>
$(document).ready(function() {
if (location.pathname.indexOf('/SearchResults.asp') != -1 ) {
$('div#content_area').css({'display','none !important'});
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 我在关闭body标签之前调用Require.js:
<script data-main="assets/scripts/src/main.js" src="assets/scripts/lib/requirejs/require.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
这是我的main.js内容:
requirejs.config({
urlArgs: "bust=" + (new Date()).getTime(), // override browser cache
});
require(['views/appView'], function (App) {
App.initialize(); // this is just to test the module is actually loading
});
Run Code Online (Sandbox Code Playgroud)
appView.js包含:
define([
'modernizr',
'jquery',
'underscore',
'backbone',
'common', // this module has about 4 other dependencies too
'dust',
'routers/main',
'views/main'
], function (Modernizr, $, _, Backbone, Common, dust, router, mainView) {
// This is supposed to load, even if jQuery loads after the DOM ready …Run Code Online (Sandbox Code Playgroud) 我有一个愚蠢的简单Jquery .js文件,我正在忙着创建,我在第一步陷入困境.
我目前设置如下所示,但每次单击页面上的唯一按钮(登录页面的提交按钮)时,它会重新加载整个页面并再次运行第一个功能.
我怎么让这个功能只运行一次
$(document).ready(function() {
//
// FUNCTIONS
//
function AllFade() {
//Hide everything
$('div').hide()
//Fade Everything in
$('div').fadeIn(1000);
//Hide All Alerts
$('.alert').hide();
}
function LoginCheck() {
//Check username and pass
}
// EVENTS
//START SEQUENCE
AllFade();
//Login check on submit
$('.btn').click(function() {
LoginCheck();
})
});
Run Code Online (Sandbox Code Playgroud)
!编辑 !!
按钮的编码就是:
<button class="btn btn-large btn-primary">Sign in</button>
Run Code Online (Sandbox Code Playgroud)
那会不会导致重装?
假设我有一些像这样的HTML元素:
<div id="wrapper">
<ul>
<li><a>Parent 1</a>
<ul>
<li><a>Child 1</a></li>
<li><a>Child 2</a></li>
<li><a>Child 3</a></li>
</ul>
</li>
<li><a>Parent 2</a>
<ul>
<li><a>Child 1</a></li>
<li><a>Child 2</a></li>
<li><a>Child 3</a></li>
</ul>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
当$(文件)准备好时,如何设置#wrapper中第一个UL元素的ID?
提前致谢!
document-ready ×10
jquery ×10
javascript ×5
domready ×2
attr ×1
dom ×1
function ×1
greasemonkey ×1
input ×1
loading ×1
pageload ×1
requirejs ×1
set ×1