通过这个:
var all = $("#innerhtml").map(function() {
return this.innerHTML;
}).get();
alert(all);
我发现:
<a class="cart-btn remove text-muted small" onclick="removeCart('fgh', 'ser');"><i class="fa fa-minus-circle"></i></a>
<a class="name-image" >
<span class="name">
<span class="quantity">28 × </span>rum ‘n’ beat</span>
</a>
<p class="comment-amount">
<span class="amount pull-right">kr3,584.00</span>
</p>
我怎样才能把它变成jQuery变量..
答案 0 :(得分:0)
您可以使用Jquery attr()
。
var result = $('.cart-btn').attr("onclick")
console.log(result);
var re = /'(.*?)'/g;
var [a,b,c] = result.match(re);
console.log(a, b, c);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="cart-btn remove text-muted small" onclick="removeCart('89', '7647966b7343c29048673252e490f736', '0');"><i class="fa fa-minus-circle"></i></a>
<a class="name-image" onclick="openMenuOptions('89', '7647966b7343c29048673252e490f736');">
<span class="name">
<span class="quantity">28 × </span>rum ‘n’ beat</span>
</a>
<p class="comment-amount">
<span class="amount pull-right">kr3,584.00</span>
</p>