选择包含相同ID的所有元素(Select all elements containing the same id)
我想迭代所有id为'#response_is_accepted'的元素,并能够将它们的值更改为某些内容。 即:val(1)。 我试过但我的尝试失败了,即:(在js文件中)
$('#response_is_accepted').each(function(i, obj) { alert($(this).text()); });
它总是在我的警报中给我未定义或空白。
<form novalidate="novalidate" class="simple_form edit_response" id="edit_response_113" action="/responses/113" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 13 hours ago </form> <br> <br> <br> <form novalidate="novalidate" class="simple_form edit_response" id="edit_response_112" action="/responses/112" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 15 hours ago </form> <br> sa<br> <br> <form novalidate="novalidate" class="simple_form edit_response" id="edit_response_111" action="/responses/111" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 15 hours ago </form>
请帮助
I want to iterate all elements that have id '#response_is_accepted' and be able to change their value to something. ie: val(1). I tried but my attempts are failing ie: (in js file)
$('#response_is_accepted').each(function(i, obj) { alert($(this).text()); });
it always gives me undefined or blank in my alert.
<form novalidate="novalidate" class="simple_form edit_response" id="edit_response_113" action="/responses/113" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 13 hours ago </form> <br> <br> <br> <form novalidate="novalidate" class="simple_form edit_response" id="edit_response_112" action="/responses/112" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 15 hours ago </form> <br> sa<br> <br> <form novalidate="novalidate" class="simple_form edit_response" id="edit_response_111" action="/responses/111" accept-charset="UTF-8" data-remote="true" method="post"><input name="utf8" type="hidden" value="✓" /><input type="hidden" name="_method" value="patch" /> <div class="form-group hidden response_is_accepted"><input class="hidden form-control" type="hidden" value="0" name="response[is_accepted]" id="response_is_accepted" /></div> <input type="submit" name="commit" value="Update Response" class="btn btn-default" /> <button type="button" class="btn btn-default btn-xs pull-right is-accepted" aria-label="Left Align" >Accept</button> jeje | about 15 hours ago </form>
Help please
原文:https://stackoverflow.com/questions/29345126
更新时间:2023-10-25 13:10
最满意答案
通过以下更改,您的代码应该可以正常工作。 我已经注意到代码中注释的变化。
With dataWs .AutoFilterMode = False With .Range("J:J") 'Use wildcard to search for word LATEX within contents of column J cells .AutoFilter Field:=1, Criteria1:="*LATEX*" End With End With totRows = dataWs.Range("J:J").Rows.Count lastRow = dataWs.Range("J" & totRows).End(xlUp).Row 'After filtering, select the visible cells in column A... Set rng = dataWs.Range("A2:A" & lastRow).SpecialCells(xlCellTypeVisible) '... and set their values to "LATEX" rng.Value = "LATEX" dataWs.AutoFilterMode = False
With the following changes, your code should work. I've noted the changes in the comments in the code.
With dataWs .AutoFilterMode = False With .Range("J:J") 'Use wildcard to search for word LATEX within contents of column J cells .AutoFilter Field:=1, Criteria1:="*LATEX*" End With End With totRows = dataWs.Range("J:J").Rows.Count lastRow = dataWs.Range("J" & totRows).End(xlUp).Row 'After filtering, select the visible cells in column A... Set rng = dataWs.Range("A2:A" & lastRow).SpecialCells(xlCellTypeVisible) '... and set their values to "LATEX" rng.Value = "LATEX" dataWs.AutoFilterMode = False
相关问答
更多-
如何将所有列数据从一个excel复制到另一个excel表(How to copy all column data from one excel to another excel sheet)[2022-02-26]
您不需要打开UnattendedData.xlsm 。 如果这是工作簿,您运行的代码已经打开。 使用Workbooks.Open的完整路径,否则会遇到问题。 尽可能使用Worksheets而不是Sheets 。 Sheets还包含图表等。 如果您使用Worksheets或Sheets始终指定工作簿,如wb.Worksheets(…) 。 否则,Excel会猜测一个工作簿并可能失败。 代码中的实际问题是Range("A:AU" & N)不是有效范围。 例如对于N=15这导致"A:AU15"无效。 它应该是"A ... -
将列从一个Excel工作表复制到另一个Excel工作表[关闭](Copy column from one Excel sheet to another Excel sheet [closed])[2022-07-15]
假设您有两个工作簿(源和目标),并且您希望将源工作簿中的A列复制到目标工作簿中的A列。 Sub CopyColumnToWorkbook() Dim sourceColumn As Range, targetColumn As Range Set sourceColumn = Workbooks("Source").Worksheets("Sheet1").Columns("A") Set targetColumn = Workbooks("Target").Worksheets( ... -
Can you try using this macro: Sub Macro1() ' ' Macro1 Macro ' Dim cell As Range For i = 1 To 50 Sheets("Sheet1").Select If Cells(1, i).Value = "Cat 2" Then Columns(i).Select Selection.Copy Sheets("Sheet2"). ...
-
Excel VBA查看工作表并将列范围复制到另一个工作表(Excel VBA look through sheets and copy column range to another sheet)[2023-04-03]
尝试这个: Sub PasteColumns() Dim arrSheets As Variant ' Define sheet names ' ------------------------ arrSheets = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec") Dim sSheet As Worksheet For i ... -
编辑:更正代码,每次获取两行; 并按照遇到的方式进行复制,而不是等到结束。 以下是您的代码的修改版本。 它打开包含“数据”的工作簿,然后创建一个新工作簿(没有用于管理是否找到现有名称的条款),然后使用搜索项加上下一行复制该行。 你表示它只需要复制它找到的FIRST。 Option Explicit Sub Apples() Dim wbThis As Workbook Dim wbData As Workbook Dim wbNew As Workbook Dim ws ...
-
1。 删除这些代码: If Entered = March Or April Or May Then ActiveSheet.Row.Value.Copy Destination:=Worksheets("Spring") If Entered = June Or July Or August Then ActiveSheet.Row.Value.Copy Destination:=Worksheets("Summer") If Entered = September Or October Or Novem ...
-
通过以下更改,您的代码应该可以正常工作。 我已经注意到代码中注释的变化。 With dataWs .AutoFilterMode = False With .Range("J:J") 'Use wildcard to search for word LATEX within contents of column J cells .AutoFilter Field:=1, Criteria1:="*LATEX*" End With End With ...
-
What:=Sheets("Sheet1").Range("A1").Value 假设“Sheet1”是您需要的工作表的名称。 复制粘贴的确切要求尚不清楚。 以下是执行复制/粘贴操作的通用代码: 示例:从单元格B1复制/粘贴到B2: Sheets("Sheet1").Range("B1").Select Selection.Copy Sheets("Sheet1").Range("B2").Select Sheets("Sheet1").Paste 或简单地说, Sheets("Sheet1").Ran ...
-
看看这是否有帮助。 我不太确定你是否只想复制名称或整行。 此代码只复制名称单元格,但很容易修改以完成整行。 Sub SrchIDs() Dim rId As Range, celS As Range, celT As Range Dim wS As Worksheet, wT As Worksheet Dim sId As String Set wS = Worksheets("Sheet1") Set wT = Worksheets("Sheet2") S ...
-
更换: LCopyToRow=2 有: With wksOutput.UsedRange LCopyToRow = .Rows.Count + .Row End With Replace: LCopyToRow=2 with: With wksOutput.UsedRange LCopyToRow = .Rows.Count + .Row End With