我有一个动态创建的页面,并显示带有价格的产品列表。由于它是动态的,因此重复使用相同的代码来创建每个产品的信息,因此它们共享标签和相同的类。例如:
<div class="product">
<div class="name">Product A</div>
<div class="details">
<span class="description">Description A goes here...</span>
<span class="price">$ 180.00</span>
</div>
</div>
<div class="product">
<div class="name">Product B</div>
<div class="details">
<span class="description">Description B goes here...</span>
<span class="price">$ 43.50</span>
</div>
</div>`
<div class="product">
<div class="name">Product C</div>
<div class="details">
<span class="description">Description C goes here...</span>
<span class="price">$ 51.85</span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
等等。
我需要对 Watir 做的是恢复带有 class="price" 的跨度内的所有文本,在此示例中:$ 180.00、$43.50 和 $51.85。
我一直在玩这样的事情:
@browser.span(:class, 'price').each do |row|但没有用。
我刚刚开始在 Watir 中使用循环。感谢您的帮助。谢谢!
我有以下HTML
<li class="post" style="width: 621px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap overlay cap-icon enlarge">
<a href="#" class="view" data-rel="lightbox" rel="lightbox">
<img width="440" height="330" src="#" class="attachment-portfolio-index wp-post-image">
</a>
</div>
</div>
<div class="detailholder">
<h4 class="post-title"><a href="#">Example Title One</a></h4>
</div>
</div>
</li>
<li class="post" style="width: 621px;">
<div class="mediaholder">
<div class="mediaholder_innerwrap overlay cap-icon enlarge">
<a href="#" class="view" data-rel="lightbox" rel="lightbox">
<img width="440" height="330" src="#" class="attachment-portfolio-index wp-post-image">
</a>
</div>
</div>
<div class="detailholder">
<h4 class="post-title"><a href="#">Example Title Two</a></h4>
</div>
</div>
</li>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用这个jQuery .post-title在a.view类中移动类li
jQuery(document).ready(function ($) { …Run Code Online (Sandbox Code Playgroud) 我使用以下行来创建与特定搜索词匹配的所有TD的数组.如果TD包含我的搜索词,则highlight添加了" " 类.
到目前为止,下面的工作正常我唯一的问题是,如果一列不包含我的搜索词,我需要添加0(一列有或没有值,但它不能在同一列中出现多次).
有问题的列是列,2, 4, 6, 8, 10, 12因此我的数组应始终包含6个值,如果其中一列不包含搜索项,则只显示0.
换句话说:我需要检查列是否包含具有"突出显示"类的TD.
我的功能:
var arr = new Array();
$('.highlight').each(function() {
arr.push($(this).text());
});
Run Code Online (Sandbox Code Playgroud)
示例HTML:
<table id="myTable">
<thead>
<tr>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
<th class="mayContainHighlight"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>5</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>7</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>3</td>
<td class="mayContainSearchTerm">other data</td>
<td>1</td>
<td class="mayContainSearchTerm highlight">search term</td>
<td>5</td>
<td class="mayContainSearchTerm">other …Run Code Online (Sandbox Code Playgroud) 我对Scala相当陌生,必须编写一个程序来计算给定整数列表的平均值。
但是,我总是收到错误消息:
foreach 不是 Int 的成员。
你们中有人知道如何解决这个问题吗?这是我的代码:
var measureResults = List(100, 36, 54, 4, 22, 37, 86, 20, 3000)
var averageResult = getAverage(measureResults)
println(averageResult)
def getAverage(measureResults: List[Int]): Double = {
var entryList = listOfValidElements(measureResults)
var average = entryList(0)
for (element <- average){
average =+ 1
var trueAverage = average/length(entryList)
return trueAverage
}
}
Run Code Online (Sandbox Code Playgroud) 我需要选择所有<select>添加了“隐藏”属性的元素。这是标记:
<optgroup label="Label 1">
<option value="978" hidden>Option 1</option>
<option value="987" hidden>Option 2</option>
<option value="987" hidden>Option 3</option>
<option value="987">Option 4</option>
</optgroup>
Run Code Online (Sandbox Code Playgroud)
我只展示了一个<optgroup>,但标记中有很多。
到目前为止,我想出了这个代码:
jQuery('optgroup').each(function() {
var options = jQuery(this).find('option');
jQuery.each(options, function(index, value) {
if ($(value).data('hidden') !== undefined) {
console.log('Found it!');
}
});
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,里面的代码条件永远不是真的。我在这里缺少什么?
是否有一种更优雅的方式来实现jQuery的以下功能?是否可以遍历所有子节点而不嵌套each函数?
$.each($('.my-class'), function () {
$.each($(this).children(), function () {
alert(this.id);
});
});
Run Code Online (Sandbox Code Playgroud)
编辑:
如果你有两个或多个带有类名的元素my-class怎么办,你如何遍历他们所有的孩子呢?
我有一个用户 ID 数组,如下所示:
var taskAssignTo = jQuery(this).attr('data-assigned');
var userArray = new Array();
userArray = taskAssignTo.split(",");
Run Code Online (Sandbox Code Playgroud)
这会获取存储在“数据分配”属性中的 id 字符串,这些 id 之间用逗号分隔。
我已尝试以下方法来检查每个复选框(如果它的值在数组中),如下所示:
jQuery( ".assignTo input" ).each(function( index ) {
var val = jQuery( this ).val();
if(jQuery.inArray(val, userArray)){
jQuery( this ).prop('checked', true);
}
});
Run Code Online (Sandbox Code Playgroud)
但是,这仅检查数组中的最后一项。
如果我喜欢console.log(val)这样:
jQuery( ".assignTo input" ).each(function( index ) {
var val = jQuery( this ).val();
console.log(val);
if(jQuery.inArray(val, userArray)){
jQuery( this ).prop('checked', true);
}
});
Run Code Online (Sandbox Code Playgroud)
我可以看到数组的所有结果都是从“数据分配”属性返回的。如果我将 console.log(val) 移至此处:
jQuery( ".assignTo input" ).each(function( index ) {
var val …Run Code Online (Sandbox Code Playgroud) 我是一名大学学生。
我必须安装 XAMPP,然后安装一个名为 PHProjekt 的程序才能将其与 XAMPP 一起使用。
这是安装 PHProjekt 以便与 XAMPP 一起使用的过程的快速视频。
https://www.youtube.com/watch?v=bfnGns5WiAY
当我到达必须登录 PHProjekt 的部分时,我无法输入并收到一条消息:
“已弃用:each() 函数已弃用。此消息将在第 66 行 C:\xampp\htdocs\phprojekt\library\Zend\Cache\Backend.php 中的进一步调用中被抑制”
这是 Backend.php 文档中的代码:
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the …Run Code Online (Sandbox Code Playgroud) if ( is_array( $u ) ) {
while( list( $key ) = each( $u ) ) {
$u = $u[$key];
break;
}
}
Run Code Online (Sandbox Code Playgroud)
当我在 laravel 框架上运行它时,我的 php 版本是 7.2 我得到了这个错误
The each() function is deprecated. This message will be suppressed on further calls
Run Code Online (Sandbox Code Playgroud)
我发现那是我必须将每个更改为 foreach 在此处输入链接描述
任何人都将代码更改给我以在 php 7.2 上工作,谢谢
我对集合进行了分组,并使用 each() 函数对其进行迭代。在每个函数中,我想将元素添加到某个数组中。但它不起作用。知道吗?
$dataSet1 = [];
$appointments = [
['department' => 'finance', 'product' => 'Chair'],
['department' => 'marketing', 'product' => 'Bookcase'],
['department' => 'finance', 'product' => 'Desk'],
];
$groupData = collect($appointments)->groupBy('department');
$groupData->each(function ($item, $key) {
Log::info($key); //Show correct output in log
array_push($dataSet1, $key); //ERROR
array_push($dataSet1, 'A');//ERROR
});
Run Code Online (Sandbox Code Playgroud)
Laravel 版本:8.35.1
each ×10
jquery ×5
loops ×3
arrays ×2
php ×2
array-push ×1
checked ×1
collections ×1
deprecated ×1
for-loop ×1
int ×1
javascript ×1
laravel ×1
parent ×1
ruby ×1
scala ×1
siblings ×1
testing ×1
watir ×1
xampp ×1