【发布时间】:2017-06-01 21:44:42
【问题描述】:
我尝试寻找答案,但没有适合我需要的答案...
这是我的代码:
<div><svg onclick="addIngredient('Bacon', -1);"><path></path></svg>
<button onclick="addIngredient('Bacon', 1);"></button><p>6 Bacon</p></div>
<div><svg onclick="addIngredient('Paprika', -1);"><path></path></svg>
<button onclick="addIngredient('Paprika', 1);"></button><p>3 Paprika</p></div>
<div><svg onclick="addIngredient('Sliced Meat', -1);"><path></path></svg>
<button onclick="addIngredient('Sliced Meat', 1);"></button><p>1 Sliced Meat</p></div>
我想捕捉
svg onclick="addIngredient(' 和'
在单词之后。例如,我想检索单词Bacon、Paprika 或Sliced Meat
我试过这样做,但它不起作用..
var stringy = '<div><svg onclick="addIngredient('Bacon', -1);"><path></path></svg>
<button onclick="addIngredient('Bacon', 1);"></button><p>6 Bacon</p></div>
<div><svg onclick="addIngredient('Paprika', -1);"><path></path></svg>
<button onclick="addIngredient('Paprika', 1);"></button><p>3 Paprika</p></div>
<div><svg onclick="addIngredient('Sliced Meat', -1);"><path></path></svg>
<button onclick="addIngredient('Sliced Meat', 1);"></button><p>1 Sliced Meat</p></div>';
var result = stringy.match("svg onclick="addIngredient(([^}]*)')");
console.log(result);
我怎样才能做到正确?
【问题讨论】:
-
先使用jsdom提取onclick属性。 (或以下段落)
标签: javascript regex string match regex-negation