简体   繁体   中英

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

I am building a button in the backend as follow:

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

This will generate the following HTML:

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

The element could be rendered as view only meaning you can view it but you can't act on it and if so I should be able to remove all the actions on it.

I did know this can be done only on the DOM level using Javascript (maybe I am wrong) maybe using .off() or setting something like this onclick="javascript: return false;" on the element.

I don't know if make it disabled or readonly will do the job.

Is Javascript/jQuery the only way ? If there is another solution please let me know

Add the disabled attribute.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM