javascript - Fetch HTML element value from json stingrigy value using Javascript
问题描述
I have object which i have converted using JSON.stingrify
{
"_originalElementInner": " <input type=\"file\" name=\"\" class=\"hidden\" id=\"file_input_two\" onchange=\"alertFilename(this.value,'cropped_two');\"> <!-- <img src=\"https://dxyz.com/tmp/5bd432ed2d8dd_img3.jpg\" alt=\"\" width=\"100%\" height=\"100%\"> --> "
}
From above i want to fetch "cropped_two", which is on
onchange=\"alertFilename(this.value,'cropped_two');
Here this.value will remain same, so if in case want to split the string .
I have tried via multiple ways by looping and other but in vain.
Anyone can help ? Thanks in advance.
解决方案
我想你只想要字符串?我想这会奏效。
let o = {
"_originalElementInner": " <input type=\"file\" name=\"\" class=\"hidden\" id=\"file_input_two\" onchange=\"alertFilename(this.value,'cropped_two');\"> <!-- <img src=\"https://dxyz.com/tmp/5bd432ed2d8dd_img3.jpg\" alt=\"\" width=\"100%\" height=\"100%\"> --> "
};
const regex = /,(.*)\);/gm;
const match = regex.exec(o._originalElementInner);
console.log(match[1]);
推荐阅读
- java - 为什么自定义信息窗口适配器只显示数组的最后一项?
- jpa - Jpa级联插入:不必要的更新?
- r - 如何最好地将嵌套列表展平为 R 中的 data.frame?
- vba - .Address 函数保存的数据类型是什么?
- c# - 转义花括号时无法字符串。格式化 C# 多行逐字字符串
- javascript - Onclick 使用 JavaScript 更改下拉菜单的宽度
- angular - Angular 应用程序未在本地浏览器中加载
- python - 如何扩展泛型类
- datatables - 我想在图标单击时打印行数据
- javascript - 在下拉列表中的 onChange 事件之前不显示默认值