dialog内嵌入 html

134 阅读1分钟

嵌入一个网页,网页内部找不到外部的div节点,想要自己在页面内添加关闭按钮,再监听,很难实现。直接在dialog内加入配置属性,在外部调节样式

function roleSwitch(uid, itemtype) {
  var base = new Base64();
  var param = encrypt('uid=' + uid + '&itemtype=' + itemtype, '');
  param = base.encode(param);
  var dialog = $.dialog({
    title: false,
    content: 'url:/html/roleSwitch.html?' + param,
    width: 800,
    height: 600,
    min: false,
    max: false,
    lock: true,
    closable: true,
    button: [
      {
        name: '×',
        callback: function () {
          this.close();
          return false;
        },
        focus: false,
        style: `
                    position: absolute;
                    top: 10px;
                    right: 10px;
                    background: none;
                    border: none;
                    font-size: 24px;
                    cursor: pointer;
                    color: #000; /* 初始颜色 */
                `,
      },
    ],
  });
  window.currentDialog = dialog;

  // 为关闭按钮添加鼠标悬浮样式
  $('.close-dialog-btn').hover(
    function () {
      $(this).css('color', 'red');
    },
    function () {
      $(this).css('color', '#000');
    }
  );
}