簡體   English   中英

如何刪除HTML元素上的所有事件?

[英]How I can remove all the events on a HTML element?

我在后端構建一個按鈕如下:

<?php
echo $this->myFormButton(
    'add_component_restriction',
    'Add',
    [
        'class'       => 'btn btn-default add_component_restriction',
        'type'        => 'button'
    ]
);
?>

這將生成以下HTML:

<button name="add_component_restriction" 
        id="add_component_restriction" 
        type="button" 
        value="Add" class="btn btn-default add_component_restriction" 
>Add</button>

元素可以呈現為視圖,這意味着您可以查看它,但您無法對其進行操作,如果是這樣,我應該能夠刪除它上面的所有操作。

我確實知道這只能在DOM級別上使用Javascript(也許我錯了)可能使用.off()或設置類似這樣的東西onclick="javascript: return false;" 在元素上。

我不知道是否disabledreadonly它將完成這項工作。

Javascript / jQuery是唯一的方法嗎? 如果有其他解決方案,請告訴我

添加disabled屬性。

<?php
echo $this->myFormButton(
    'add_component_restriction',
    'Add',
    [
        'class'       => 'btn btn-default add_component_restriction',
        'type'        => 'button',
        'disabled'    => 'disabled'
    ]
);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM