here is my case:
<html>
<body>
<head>
...
<script>
$(function(){
$('.do-tip').qtip({
content: 'This is a tip of active hovered element',
show: 'mouseover',
hide: 'mouseout',
})
});
</script>
</head>
<body>
<a href="http://www.google.com" class="do-tip">google</a>
<input type="button" value="load div by ajax" />
<div> <!-- this div loaded by ajax -->
<div>
<a href="http://www.yahoo.com" class="do-tip">yahoo</a> <!-- HOW TO HERE, run the existing script only for this part, JQUERY UNCLE must have a solution-->
</body>
</html>
any ideas?
Run Code Online (Sandbox Code Playgroud) 我在这里做错了什么?为什么writeQuestions不加载运行(不是onclick..)?
$(document).ready(function() {
$.getJSON("JavaScript/questions.json", function(data) {questions = data;});
$("#start").one("click" , writeQuestions);
writeQuestions();
});
Run Code Online (Sandbox Code Playgroud)
(该.one()行在我的代码中被注释掉了)
当我这样做时:window.onload=writeQuestions;它工作正常..
我正在尝试在加载页面时加载一些jquery javascript,但它总是加载两次.我正在使用jquery 1.7.2和jquery mobile 1.1.0.我尝试了这3种不同的方法,但它总是加载脚本两次.
$(document).bind("ready", function() { }
$(document).ready(function() { }
$(document).live('pageinit',function(event) { }
Run Code Online (Sandbox Code Playgroud)
编辑:我解决了,狗屎!我百分百肯定这个错误会发生在其他人身上,我很抱歉这个愚蠢的问题.
在我的应用程序中,我每1000ms调用一个方法来检查文件readyState.以下是我正在使用的代码,
var success=setInterval(""CheckState()"",1000);
function CheckState(){
if($get('businessDownl').document.readyState=="interactive" ||
$get('businessDownl').document.readyState=="complete"){
alert("Great");
clearInterval(success);
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在IE浏览器中工作正常.但在Firefox和Chrome浏览器中失败.我$get('businessDownl').readyState也尝试使用
,它是打印为undefined.有谁能告诉我如何在上面的场景中使用readyState for FF和chrome?
我想改变这行代码来运行准备和更改
jQuery('#form_auction_type').change(function(e) {
Run Code Online (Sandbox Code Playgroud)
编辑行到
jQuery('#form_auction_type').ready(function(e) {
Run Code Online (Sandbox Code Playgroud)
解决了我的问题,但我仍然需要.change功能
整个代码:
jQuery('#form_auction_type').change(function(e) {
if (jQuery('#form_auction_type').val() == '2') {
jQuery('#form-row-rapper-price_bin').show();
} else {
jQuery('#form-row-rapper-price_bin').hide();
Run Code Online (Sandbox Code Playgroud)
我怎样才能准备好并改变同一条线!!
为了优化我的文档的负载,我使用像这样加载jquery异步
<script async type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
然后我使用jquery调用脚本:
<script type="text/javascript">
jQuery(document).ready(function() {
App.init();
OwlCarousel.initOwlCarousel();
FancyBox.initFancybox();
StyleSwitcher.initStyleSwitcher();
});
</script>
Run Code Online (Sandbox Code Playgroud)
它返回我没有定义jquery.
我不知道我应该使用什么,我虽然.readyfunction会等到所有文件都被加载后再调用它.
对于boostrap库来说,它告诉我没有定义jquery.
我试过要求脚本最后加载,但它仍然无法正常工作.
任何帮助将不胜感激.
我正在尝试获取一种能够等待元素已经存在于 DOM 中的方法。我读过一些关于 的文章MutationObserver,并且我得到了这个方法,它应该可以完成我所需要的:
const waitForElement = async (queryString) => {
return new Promise((resolve) => {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const nodes = Array.from(mutation.addedNodes);
nodes.forEach((node) => {
console.log('NODE CUSTOM', node);
if (node.matches && node.matches(queryString)) {
observer.disconnect();
resolve(node);
}
});
});
});
observer.observe(document.documentElement, {
childList: true,
subtree: true,
});
});
};
Run Code Online (Sandbox Code Playgroud)
然后,我可以这样简单地使用它:
await waitForElement('#id-of-element');
Run Code Online (Sandbox Code Playgroud)
问题是它实际上没有按预期工作:console.log仅记录“父母”元素,如果要搜索的元素位于树的深处,则似乎不会记录它(这正在更复杂的应用程序中使用) ,所以它可能与异步调用等有关)。
然而,我发现,我只需要查看实际元素是否在 DOM 中,而不是遍历突变和节点数组,所以我实现了这个:
const waitForElement = async (queryString) => { …Run Code Online (Sandbox Code Playgroud) javascript asynchronous document-ready mutation-observers queryselector
文档是否有办法准备调用php脚本?
我想做这样的事情.
<script>
$(document).ready(function($) {
<?php require("readenglish.php"); ?>
<?php require("readfrench.php"); ?>
<?php require("readspanish.php"); ?>
<?php
$opload = $_GET['opload'];
if ($opload == "reade") {
}
else if ($opload == "readf") {
echo "<script type=\"text/javascript\">\n";
echo "document.f1.r1[0].checked = false;\n";
echo "document.f1.r1[1].checked = true;\n";
echo "SelectRead();\n";
echo "</script>";
}
?>
});
</script>
Run Code Online (Sandbox Code Playgroud)
这三个php脚本创建div并从外部域php脚本向它们添加信息.
可以在同一页面上多次调用$(document).ready吗?如果是这样,如何解决运行代码的顺序,这是否有任何影响
我在我的rails应用程序中使用jQuery.我通过应用程序使用了几个级别的javascript,所有这些都使用jQuery.
例如,我有一些默认代码淡出我的application.js中的Flash Notices我有一个包含在所有Project模型视图中的projects.js文件,并且我有一个仅包含在视图中的project/edit.js通过编辑动作.
在我使用的所有三个js文件中:
$(document).ready
{
//Do something
}
Run Code Online (Sandbox Code Playgroud) 毫无疑问这很简单,但是我对jquery缺乏了解,这对我来说很复杂.基本上我有这个代码:
$(document).ready(
function() {
$( "#remove")
.click(function() {
alert("I have been clicked!");
$(this).parent().parent().remove();
});
});
Run Code Online (Sandbox Code Playgroud)
我在表格中添加了一个按钮,用于删除它的行(参见上面的代码).按钮如下:
<td ><button id='remove' type='button'>Remove</button></td>
Run Code Online (Sandbox Code Playgroud)
但是,点击时它什么都不做.我认为这可能与文档加载后创建按钮的事实有关...但不知道如何处理它.
document-ready ×10
jquery ×7
javascript ×6
ajax ×1
async-await ×1
asynchronous ×1
button ×1
document ×1
load ×1
onload-event ×1
php ×1