onclick窗口.打开并警报

onclick window.open AND alert

本文关键字:窗口 onclick      更新时间:2023-09-26

使用JavaScript,我将一些HTML代码放入div,其中onclick我想运行一个文件并提醒用户。我遇到的问题是,它将运行程序很好,但不会发出警报。下面是我到目前为止的代码:

function novpn() {
    var output = document.getElementById("main");
    document.getElementById('main').scrollIntoView();
    var sentence ="<div id='continue' onclick='window.open('"filepath"); alert('CLICK RUN');'></div>";
    output.innerHTML = sentence;
}

问题是你如何转义你的sentence html。

function novpn() {
  var output = document.getElementById("main");
  document.getElementById('main').scrollIntoView();
  var sentence ="<div id='continue' onclick='window.open('"filepath'"); alert('"CLICK RUN'");'>CLICK ME</div>";
  output.innerHTML = sentence;
}

应该工作。详见:http://plnkr.co/edit/Q4I0JNDXjLA094stYAkN?p=preview