简体   繁体   中英

onClick event doesn't work in Firefox

I have a function previewPost for the onClick event but it doesn't work on Firefox Browser.. even if I call a single alert() in the same event doesn't work.

<script type="text/javascript">

 function previewPost() {
          Ext.define('WindowPost', {
              extend: 'Ext.window.Window',

              requires: [
                  'Ext.form.field.Text'
              ],

              height: 250,
              width: 400,
              title: 'My Window',

              initComponent: function() {
                  var me = this;

                  Ext.applyIf(me, {
                      items: [
                          {
                              xtype: 'textfield',
                              fieldLabel: 'ID',
                              value: this.algo
                          }
                      ]
                  });

                  me.callParent(arguments);
              }

          });
          var win = Ext.create('WindowPost',{"algo": "input"});
          win.show();
      }

       Ext.onReady(function(){

         Ext.define('DataView', {
              extend: 'Ext.view.View',
              alias: 'widget.dataview',

              requires: [
                  'Ext.XTemplate'
              ],

              id:'dataView2',
              height: 25,
              width: 1800,
              //border:true,
              emptyText: '',
              itemSelector: 'div.ticket-wrapper2',
              store:'storee2',
              initComponent: function() {
                  var me = this;

                  Ext.applyIf(me, {
                      itemTpl: [
                          '<tpl>',
                          '     <div class="ticket-wrapper2" onclick="previewPost()" >{area_comun.nombre}</div> ',
                          '</tpl>'


                      ]
                  });

                  me.callParent(arguments);
              }

          });
          var dta = Ext.create('DataView');
          dta.render('content');

});
 </script>

Here's where I call the function

itemTpl: [
            '<tpl>',
            '     <div class="ticket-wrapper2" onclick="previewPost()" >{area_comun.nombre}</div> ',
                          '</tpl>'


                      ]

The onclick HTML attribute is very old and should not be relied upon. Instead, give an id to your div:

<div id="wrap_1" class="ticket-wrapper2">

Then add a click event listener, wrapped in a page load event listener (so it won't matter where you put it), somewhere in your javascript:

document.addEventListener('DOMContentLoaded', function(){
    document.getElementById('wrap_1').addEventListener('click', previewPost);
});

This will work for every browser back to IE 9.

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