【问题标题】:display modal jquery by click通过单击显示模态 jquery
【发布时间】:2015-07-01 23:59:01
【问题描述】:

如何通过单击图像来显示我的 jQuery 模态?看看这个:

实际上,我正在尝试在模态框中显示 JQplot 图表。单击图像后,应显示该框

在同一页上..

<div id="dialog" title="Basic dialog">
 <div id="chart1" style= "width:40%;height:200px"> </div>
</div>
<img id="imgg" src = "stats_matching/gprier.gif" alt = "perso">


  <script>
  $(document).ready(function(){
    $.jqplot.config.enablePlugins = true;
    var s1 = [2, 6, 7, 10];
    var ticks = ['a', 'b', 'c', 'd'];

    plot1 = $.jqplot('chart1', [s1], {
        // Only animate if we're not using excanvas (not in IE 7 or IE 8)..
        animate: !$.jqplot.use_excanvas,
        seriesDefaults:{
            renderer:$.jqplot.BarRenderer,
            pointLabels: { show: true }
        },
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: ticks
            }
        },
        highlighter: { show: false }
    });

});     

        $("#dialog").hide();
        $('#imgg').click(
            function() {
                $(this).data('clicked',true);
            }
        );

        if($('#imgg').data('clicked')) {
                console.log('refefez');
                $("#dialog").show().dialog();

        }


  </script>

【问题讨论】:

  • 创建一个 jsfiddle,jsfiddle.net
  • 你可以先把你所有的js代码放在document ready函数里面。

标签: javascript jquery


【解决方案1】:

你需要有一个监听变化的函数 数据属性。

  ` $(document).on('data-attribute-changed', function() {
       if($('#imgg').data('clicked')) {              
            $("#dialog").show().dialog();

        }         
  });`

谢谢, 查尔斯。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多