我正在使用$().each()循环浏览一些项目.我想确保此脚本之后的操作仅在each()完成后执行.
例:
$('something').each(function() {
// do stuff to items
});
// do something to one of these items
$('item').etc
Run Code Online (Sandbox Code Playgroud)
它似乎在这一点上起作用,因为它是一个非常基本的动作.但有时候它会失败并且看起来each()部件仍然很忙,导致后续脚本的each()操作被操作覆盖.
那么......这可能吗?或者,每个()函数下面的代码总是在前一个代码之后执行.我知道例如AJAX调用具有"成功"功能,强制代码仅在父动作完成时执行.这需要/可能吗?我尝试了类似下面的内容,但这似乎不起作用:
$('something').each(function() {
// do stuff to items
}, function () {
// do stuff when the each() part has completed
});Run Code Online (Sandbox Code Playgroud) 我有一些简单的表(多个,所有与class ="parent")有多<tr> 行.<td>这些行中的单元格具有自己的表格.我想针对<tr>该行第一(父)表,如下所示:
HTML:
<table class="parent">
<tr> <-- match with :first
<td>
<table>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
</td>
</tr>
<tr> <-- match with :last
<td>
<table> <-- so ignore this child ..
<tr><td></td></tr>
<tr><td></td></tr> <-- .. and do NOT match this <tr> with :last
</table>
</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('table.parent').each(function() {
$(this).find('tr:first').dostuff();
$(this).find('tr:last').dostuff();
});Run Code Online (Sandbox Code Playgroud)
该:first <tr>精品工程,因为这永远是<tr>父母的.但是当我尝试选择它时:last <tr>,它将匹配<tr>嵌套表的最后一个,而不是<tr>父表的最后一个.我怎么能告诉jQuery只查看<tr>父表中的s,并且不要在可能的子表中进一步搜索?
我目前正在使用Prototype,但我想将此函数重写为jQuery:
function post(div,url,formId) {
new Ajax.Updater(div, url, {
asynchronous:true,
parameters:Form.serialize(formId)
});
}Run Code Online (Sandbox Code Playgroud)
与它一起使用的HTML示例:
<form method="post" action="" id="foo"
onsubmit="post('result','getdata.php','foo');return false;">
<input type="text" name="data" />
</form>
<div id="result"></div>Run Code Online (Sandbox Code Playgroud)
我一直在看jQuery.load()和jQuery.post(),但我不确定使用哪一个以及如何使用.
在此先感谢您的帮助.
我正努力让以下工作,但我不知所措......
class Foo {
public $somethingelse;
function __construct() {
echo 'I am Foo';
}
function composition() {
$this->somethingelse =& new SomethingElse();
}
}Run Code Online (Sandbox Code Playgroud)
class Bar extends Foo {
function __construct() {
echo 'I am Bar, my parent is Foo';
}
}Run Code Online (Sandbox Code Playgroud)
class SomethingElse {
function __construct() {
echo 'I am some other class';
}
function test() {
echo 'I am a method in the SomethingElse class';
}
}Run Code Online (Sandbox Code Playgroud)
我想要做的是在类Foo中创建SomethingElse类的实例.这适用于=&.但是当我用类Bar扩展类Foo时,我认为子类继承了父类的所有数据属性和方法.但是,似乎$this->somethingelse在子类Bar中不起作用:
$foo = new Foo(); // …Run Code Online (Sandbox Code Playgroud)