我有一个小问题。当我单击带有onclick =“ show_order_info(numbers);的元素时,如何触发另一个功能?” Onclick属性有随机数,请尝试使用正则表达式...
我需要在单击时执行标准函数,然后单击我的函数,我无权访问原始js,我只想为我改善功能
但问题是未捕获ReferenceError:未定义show_order_info
$('.redbutton').on('click', /show_order_info\(\d+\)\;/).innerHTML = "YOU CLICKED ME!";
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="javascript:void(0);" onclick="show_order_info(2588093);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf("/ajax_partner_orderinfo?uoid=2588093&print=1")" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>
<a href="javascript:void(0);" onclick="show_order_info(2797617);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf("/ajax_partner_orderinfo?uoid=2797617&print=1")" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>
您不单击就执行,而是将正则表达式作为逗号分隔的语句来执行
也许你是说
const yourFunction = but => but.textContent = "you clicked me";
const show_order_info = order => console.log(order)
const printPdf = url => console.log(url)
$('.redbutton').each(function() {
// const click = this.onclick.toString().match(/\{\s+?(.*?)\s+?\}/)[1];
const click = this.onclick;
this.onclick=null;
console.log(click)
$(this).on("click", function() {
yourFunction(this)
click()
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="javascript:void(0);" onclick="show_order_info(2588093);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf("/ajax_partner_orderinfo?uoid=2588093&print=1")" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>
<a href="javascript:void(0);" onclick="show_order_info(2797617);" class="redbutton" style=""><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Show Order</a>
<a href="javascript:void(0);" onclick="printPdf("/ajax_partner_orderinfo?uoid=2797617&print=1")" class="redbutton"><img src="/images/admin/pdf_ico.png" style="vertical-align: initial; height: 16px; width: 16px">Print Order</a>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句