簡體   English   中英

使用 JavaScript 如何通過 ID 獲取此 HTML 元素內部的字符串?

[英]Using JavaScript how can I get the string inside of this HTML element by ID?

使用 JavaScript,我怎樣才能得到這個 HTML 元素內部的字符串,id 是 recItemString_GPLA\|input? 在元素內部有一個我試圖捕獲的帶有“qty”(不帶引號)的字符串。 當我檢查我得到的元素時:

<input data-oj-internal="" type="text" readonly="" placeholder="" class="oj-inputtext-input oj- 
component-initnode" id="recItemString_GPLA|input"> == $0.

在 DevTools 中的那個元素之上有:

<oj-input-text :id="[[fieldId()]]" validators="[[validators]]" on-value- 
changed="[[valueChanged.bind($data)]]" on-valid-changed="[[validChanged]]" 
value="{{value}}" required="[[required]]" readonly="[[readOnly]]" messages- 
custom="[[messagesComputed]]" display-options="[[displayOptions]]" help=" 
[[help]]" id="recItemString_GPLA" class="oj-inputtext oj-form-control oj- 
component oj-read-only oj-complete"><input data-oj-internal="" type="text" 
readonly="" placeholder="" class="oj-inputtext-input oj-component-initnode" 
id="recItemString_GPLA|input"></oj-input-text>

我無法收集元素內的字符串以將其顯示到控制台。

使用插件 SelectorGadget 元素 XPath 為: //*[(@id = "recItemString_GPLA\|input")]

當我嘗試直接向控制台查詢 oj-input-text 時,控制台返回 [Object NodeList]

這是檢查元素的屏幕截圖: 屏幕2

使用 jQuery 您可以轉義如下特殊字符:

$('#recItemsString\\_GPLA\\|input');

我真的不確定應該生成哪個文本。 在下面的代碼片段中,我添加了一個要顯示的輸入值。

 const qs=s=>document.querySelector(s); console.log(qs('#recItemString\\_GPLA\\|input').value)
 <oj-input-text:id="[[fieldId()]]" validators="[[validators]]" on-value-changed="[[valueChanged.bind($data)]]" on-valid-changed="[[validChanged]]" value="{{value}}" required="[[required]]" readonly="[[readOnly]]" messages-custom="[[messagesComputed]]" display-options="[[displayOptions]]" help="[[help]]" id="recItemString_GPLA" class="oj-inputtext oj-form-control oj-component oj-read-only oj-complete"> <input data-oj-internal="" type="text" value="some text inside..." readonly="" placeholder="" class="oj-inputtext-input oj-component-initnode" id="recItemString_GPLA|input"> </oj-input-text>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM