我有一個html標簽"tabbedCell"回傳,可以看到下面的內容:
< input type="text"/span> data- 行-id="12630" class="edit numeric ui-draggable ui-draggable-handle" data-field="May"/span> value="135"/span> style="position: relative; cursor: cell;">
我試圖在這個元素上設定焦點,然而我已經確認在設定焦點后,焦點元素是未定義的。有什么建議嗎?
編輯:我的頁面上有多個輸入,所以答案不會起作用。如果存在多個輸入元素,我需要關注這個特定的輸入元素。
console.log(tabbedCell)
$(tabbedCell).focus()。
console.log(($(':focus') [0])。
uj5u.com熱心網友回復:
添加id="sample_input"
。< input type="text" id="sample_input" data-row-id="1263" string">"12630" class="Edit numeric ui-draggable ui-draggable-handle" data- field="May"/span> value="135"/span> style="position: relative; cursor: cell;">
這就是你的重點
# -> Means id
$("#sample_input"/span>).focus()。
編輯:由于你不想添加另一個ID,所以使用這個:
。$("input[data-row-id=12630]"/span>).focus()。
編輯2:像這樣
$("input[data-row-id=12630][data-field=May]"/span>).focus()。
uj5u.com熱心網友回復:
使用元素的ID或類來代替,像這里你可以使用 "編輯"。
$(".edit"/span>).focus()。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/331325.html
標籤:
上一篇:如何在Python中用cv2改變一個RGB通道的值?
下一篇:如何只用vanillaJavaScript和Node-API將多個div-elements包裹在另一個元素-節點上?
