Llamar a objeto desde funcion onclick javascript?

Realizo una pequeña practica e intento llamar a un objeto desde onclcik en un botón, puedo llamar a la función directamente pero quería hacerlo llamando al objeto para practicar, pero me da error. He revisado mi sintaxis y no encuentro error (al parecer) entonces quisiera saber si tengo algo mal o esto no es posible? Este es mi código.

Codigo en html del input

 <button onclick = "Usuario.total();"class = "Aceptar" id = "aceptar">Listo</button>  
 var Usuario = new Auto();  
 class Auto {   function total(){     alert('hola'); }  }   

El error que me aparece es: SyntaxError: fields are not currently supported

y que Auto no está definido.

Is it possible to pass a parameter to image onclick event in c# MVC?

I need to pass a param to the image onclick event. I know how to do it using a script and the controller, but I would like to know if it can be done directly in the view ? I’ve searched the SO and tried some examples but nothing worked so far.

@{string test = "kkkk";} <img onclick="alert('' + @test + '')" /> <img onclick="alert(@test)" />  @{string test = "alert('kkkk')";} <img onclick="alert(@test)" /> 

Custom Button with Onclick , Hide Onclick Event

I’ve created a Custom Button . I hook it up with a Grid . And I’ve made custom code for the On-click event .

The Code bellow is simplified for easier understanding .

Everything works, if I click the Button the Message is shown . But since I am running a lot more code here . I would like to hide if possible all events for this button . Is that possible even if I am actually using TcxButton as my Parent Class ?

unit cxGridButton;  interface  uses   System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, cxButtons,   cxGridDBTableView, Dialogs;  type   TcxGridButton = class(TcxButton)   private     FGridView : TcxGridDBTableView;    protected     { Protected declarations }   public     { Public declarations }      procedure Click; override;   published     property DBGridView : TcxGridDBTableView read FGridView write FGridView;   end;  procedure Register;  implementation  procedure TcxGridButton.Click; begin   inherited; // call the inherited Click method.    ShowMessage('AHA'); end;  procedure Register; begin   RegisterComponents('James', [TcxGridButton]); end;  end. 

¿Porqué no me funciona onclick?

Este es el código, quiero que al clickear en ¿Quieres reservar? se muestre el div “calendario_reserva”, pero algo falla:

HTML:

<input type="checkbox" id="activar_reserva" onclick="activar_reserva();"> <label>¿Quieres reservar?</label>  <div class="" id="calendario_reserva"> AQUI UN CALENDARIO PARA SELECCIONAR LA FECHA. </div>  <br/> <button type="submit" name="action" value="contestar" class="form-control fondo2 color1" style="margin-top:10px;">Enviar</button>  </form> 

JS:

activar_reserva();  function activar_reserva(){     if(document.getElementById('activar_reserva').checked){          document.getElementById('calendario_reserva').style.display = "unset";      }else{          document.getElementById('calendario_reserva').style.display = "none";      } } 

https://jsfiddle.net/ogdbt09v/

onclick на теге

Необходимо посадить событие с помощью атрибута onclick на тег <p>. Объясните пожалуйста почему в данном случае функция не вызывается?

function close() {    console.log('click'); }
<p onclick="close()">Клик</p>

Определение аргументов onclick в createElement

Я изучаю react и сейчас пытаюсь решить проблему, но не знаю как это сделать, я сделал функцию которая открывает giftbox, сделал функцию которая запускает конфити, отдельно они работают друг от друга, а сделать чтобы при открытии ящика выветало конфети не получается, не могу понять как определить событие для onclick, чтобы оно запустило функцию emit()

// отрисовка ящика var cGiftBox = function (_a) {   var wasOpen = _a.wasOpen,open = _a.open,dispatch = _a.dispatch;   return React.createElement("div", { className: "floor" },   React.createElement("div", { className: "box" },   open ?   React.createElement("button", { className: "heart-gift", }, "hello") :   React.createElement(React.Fragment, null),      React.createElement("div", { className: open ?     'lid open' :     wasOpen ?     'lid close' :     'lid', onClick: function (e) {return dispatch(toggleBox());} },    React.createElement("div", { className: "qcube" }, open ? '!' : '?'),   React.createElement("div", { className: "face ltop" }),   React.createElement("div", { className: "face lleft" }),   React.createElement("div", { className: "face lright" })),   React.createElement("div", { className: "face top" }),   React.createElement("div", { className: "face left" }),   React.createElement("div", { className: "face right" }) )); };  // запуск конфети function emit() {   var container = document.getElementById("confetti-container");   var containerRect = container.getBoundingClientRect();   var containerData = {     x: containerRect.left,     y: containerRect.top,     height: containerRect.right - containerRect.left,     width: containerRect.bottom - containerRect.top };

How to go initial state after onClick function fired in reactJS?

I have made copy to clipboard component. It’s working fine. But i want to make it goes to initial state after copied the text. That’s mean before onClick event it will show on hover “Copy to Clipboard” and when it clicked it will show “Copied to clipboard” and goes to initial state (Copy to Clipboard) and if i click again then onClick event will be fire again.

Here is my working code

Thanks in advance.

jest plus react – testing an onClick method

I am kinda new to jest and unit testing in general. I created a component that has a click handler. I would like to check that when I clicked it whether the state updated. However it always tells me “TypeError: Cannot read property ‘equal’ of undefined”. if I try to log the fidn result it doesn’t do anything. but i know there is a node inside of it because if i change the name it gives the error: “expect node to be 1 but found 0” Would anyone be kindly enough to give any pointers? cheers!

The component

import React from "react"; import PropTypes from "prop-types"; import { getFlag } from "../helpers/helperFucntions"; import CountrySportDetails from "./CountrySportDetails"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import {     faCaretDown,     faCaretUp,     faMedal } from "@fortawesome/free-solid-svg-icons";  class CountryListComponent extends React.Component {     state = {         detailsOpenStatus: false     };      toggleDetailsOpenStatus = () => {         this.setState({ detailsOpenStatus: !this.state.detailsOpenStatus });     };      render() {         const { countryDetails, sportslist } = this.props;         const flag = getFlag(countryDetails.c_Name);          let goldMedalCount = 0;         let silverMedalCount = 0;         let bronzeMedalCount = 0;          sportslist.map(sport => {             goldMedalCount += sport.GoldMedalList.length;             silverMedalCount += sport.SilverMedalList.length;             bronzeMedalCount += sport.BronzeMedalList.length;         });          const medals = (             <div className="country-listitem__medal-container">                 <div>                     <FontAwesomeIcon icon={faMedal} className="gold" /> {goldMedalCount}                 </div>                 <div>                     <FontAwesomeIcon icon={faMedal} className="silver" />{" "}                     {silverMedalCount}                 </div>                 <div>                     <FontAwesomeIcon icon={faMedal} className="bronze" />{" "}                     {bronzeMedalCount}                 </div>             </div>         );          console.log("medals", goldMedalCount, silverMedalCount, bronzeMedalCount);          const caret =             this.state.detailsOpenStatus === false ? (                 <FontAwesomeIcon icon={faCaretDown} />             ) : (                 <FontAwesomeIcon icon={faCaretUp} />             );          return (             <div                 className="country-listitem__countainer"                 onClick={this.toggleDetailsOpenStatus}             >                 <div className="country-listitem__flag-container">{flag}</div>                  <div className="country-listitem__country-name">                     {countryDetails.c_Name}                     {medals}                 </div>                  <div className="country-listitem__caret">{caret}</div>                  <CountrySportDetails                     sportslist={sportslist}                     openDetailsStatus={this.state.detailsOpenStatus}                 />             </div>         );     } }  CountryListComponent.propTypes = {     countryDetails: PropTypes.object.isRequired,     sportslist: PropTypes.array.isRequired };  export default CountryListComponent; 

The test

import React from "react"; import ReactDOM from "react-dom"; import CountryListComponent from "./CountryListComponent";  import { configure, shallow, mount } from "enzyme"; import Adapter from "enzyme-adapter-react-16"; import { isExpressionWrapper } from "@babel/types";  configure({ adapter: new Adapter() });  test("renders without crashing", () => {     shallow(<CountryListComponent countryDetails={{}} sportslist={[]} />); });  test("test the click handler", () => {     const container = mount(         <CountryListComponent countryDetails={{}} sportslist={[]} />     );     container.find(".country-listitem__countainer").simulate("click");     container.update();      expect(container.state("detailsOpenStatus")).to.equal(true); }); 

enter image description here