单击按钮时如何显示此弹出窗口

时间:2015-01-13 15:36:45

标签: javascript jquery html

脚本代码:

<script type="text/javascript">
var uid = 'xxxxx';
var wid = 'xxxxx';
</script>
<script type="text/javascript" src="http://cdn.popcash.net/pop.js"></script>

按钮代码:

<div>
<input type="submit" class="btn" value="Get reward!">
</div>

我在这个...请帮忙!!

4 个答案:

答案 0 :(得分:0)

<div>
   <input type="submit" class="btn" onclick="alert('this is your msg.');" value="Get reward!">
</div>

答案 1 :(得分:0)

<input type="submit" id="button1" value="Click Me" onclick="alertThis()">
<script type="text/javascript">
    function alertThis(){
        var var1 = "xxxx";
        var var2 = "yyyy";
        alert(var1+var2);
    }
</script>

应该这样做。

答案 2 :(得分:0)

您的HTML:

<script type="text/javascript">
var uid = 'xxxxx';
var wid = 'xxxxx';
</script>
<input type="submit" class="btn" value="Get reward!" onclick="addPopup()">

你的JS:

function addPopup() {
    var script = document.createElement('script')
    script.setAttribute('src', 'http://cdn.popcash.net/pop.js');
    script.setAttribute('type', 'text/javascript');
    document.getElementsByTagName('head')[0].appendChild(script)
}

如果包含

,pop.js将自动初始化,这是有效的

答案 3 :(得分:0)

按下按钮时似乎要执行脚本,这是一种方法:

<script>
  var uid = 'xxxxx';
  var wid = 'xxxxx';

  function showPopup() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://cdn.popcash.net/pop.js';

    document.getElementsByTagName('head')[0].appendChild(script);
  }
</script>

<div>
  <input type="submit" class="btn" value="Get reward!" onclick="showPopup();">
</div>

虽然我必须告诉您,您应该知道可能存在安全漏洞,执行外部JavaScript文件可能会打开。类似的案例可在Dynamically added script will not execute

找到