Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript-需要从字符串中提取数据_Javascript_Jquery_Ajax_String - Fatal编程技术网

javascript-需要从字符串中提取数据

javascript-需要从字符串中提取数据,javascript,jquery,ajax,string,Javascript,Jquery,Ajax,String,嗨,我有一个基于datatables的表,用于保存数据。我需要能够从下面的字符串中获取值,到目前为止我已经能够做到这一点 <input name="jobNo" value="job_no_123" />job_no_123 job\u no\u 123 我需要能够获取名称和值,并将其存储到单独的变量中,然后将这些变量传递给其他操作 但是,我也需要在页面上捕获另外4个字段: <input name="item_1" value="data1" />data1 <

嗨,我有一个基于datatables的表,用于保存数据。我需要能够从下面的字符串中获取值,到目前为止我已经能够做到这一点

<input name="jobNo" value="job_no_123" />job_no_123
job\u no\u 123
我需要能够获取名称和值,并将其存储到单独的变量中,然后将这些变量传递给其他操作

但是,我也需要在页面上捕获另外4个字段:

<input name="item_1" value="data1" />data1
<input name="item_2" value="data2" />data2
<input name="item_3" value="data3" />data3
<input name="item_4" value="data4" />data4
data1
数据2
数据3
数据4
除此之外,这将只是一行中的数据,我也需要对多行执行此操作。但我需要从某个地方开始

请帮忙


谢谢

我不确定您需要什么,但这里有一个代码应该会有所帮助

$('input').each(function(i, val){
    $(this).attr('name'); // will get the attribute name
    $(this).attr('value'); // will get the attribute value
    $(this).attr('text');  // will get the text inside the input
});

这个正则表达式可以从代码中找到值。但是,它假设输入严格采用该格式,即使空白也没有变化


值将在捕获的组1和组2中


注意:我知道不应该使用正则表达式来解析HTML,但是如果输入足够严格,它就可以工作。

为什么?当jQuery可用时,为什么要这样做呢?这个问题提到的是“字符串”中的输入,而不是DOM中的输入。(虽然字符串很可能是从DOM中获得的。)您可以轻松地将该字符串更改为DOM。不过,RegEx可以完成这项工作。