【问题标题】:Including onclick action in href在 href 中包含 onclick 操作
【发布时间】:2020-02-17 17:27:15
【问题描述】:

我有一个 woocommerce 网上商店,我尝试将 setAttribute('open', 'true') 包含到变体标签中。

但是,返回标签时会出错: 解析错误:语法错误,第 95 行 .../shortcode.php 中的意外“打开”(T_STRING)

我改变了双引号的引号,反之亦然,但没有解决。

add_filter( 'woocommerce_attribute_label' , 'modify_the_attribute_filter' , 10 , 3 );

function modify_the_attribute_filter( $label , $name , $product ){
$id = get_the_id();

if ( ($id ==189 || $id == 32 || $id == 754) && !is_admin() ){

if( $label == 'Lunch' ){
    $label .= '<a class="extra_label" href="#anchor" onclick="det.setAttribute('open', 'true'); return false;">i</a>';
}
else {
    $label .= '<a class="extra_label" href="#anchor">i</a>';
}
} 
return $label;
 }

目标是每个变体标签都包含一个可点击的项目,该项目是页面上某个点的锚点,同时打开一个详细信息摘要框。

【问题讨论】:

    标签: woocommerce variations setattribute


    【解决方案1】:

    您是否尝试过如下转义引号?

    $label .= '<a class="extra_label" href="#anchor" onclick="det.setAttribute(\'open\', \'true\'); return false;">i</a>';
    

    【讨论】:

    • 虽然没有报错,但是url里面什么都没有传递。我认为这个过滤器有一些消毒作用......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    相关资源
    最近更新 更多