首页 > 解决方案 > 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.

标签: javascripthtml

解决方案


我想你只想要字符串?我想这会奏效。

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]);


推荐阅读