通过选择复选框

问题描述:

通过选择复选框

function msg() 
 
{ 
 
    if (document.getElementById('c1').checked); 
 
    alert("suggest an update"); 
 
    }
<input class="form-control" type="checkbox" id="c1" onclick="msg()" name="like"/>
创建弹出的形式动态

+2

那就需要更多的解释去做。像其他网站的示例 – shanks

+0

您可以使用JavaScript库,如jQuery – Sayed

你可以用不同的方式形式弹出,其中之一是使用jQuery

这里是一个example,做你想做的事。

下面将生成与一个文本输入元件的形式,很容易扩展,要包括许多其它元件。不能给任何jQuery的例子因为我不使用它。

<script type='text/javascript' charset='utf-8'> 
     function msg(e) { 
      var id='bob'; 
      var el=e.target || e.srcElement; 
      if(el.checked){ 

       var cont=document.getElementsByTagName('body')[0];     
       var form=addNode('form',{id:id},cont); 
        form.style.width='500px'; 
        form.style.height='500px'; 
        form.style.zIndex=10; 
        form.style.border='1px solid black'; 
       addNode('input',{type:'text',name:'fred'},form); 
      }else{ 
       if(document.getElementById(id)) document.getElementById(id).parentNode.removeChild(document.getElementById(id)); 
      } 
     } 
     function addNode(t, a, p) { 
      var el = (typeof(t)=='undefined' || t==null) ? document.createElement('div') : document.createElement(t); 
      for(var x in a) if(a.hasOwnProperty(x) && x!=='innerHTML') el.setAttribute(x, a[ x ]); 
      if(a.hasOwnProperty('innerHTML')) el.innerHTML=a.innerHTML; 
      if(p!=null) typeof(p)=='object' ? p.appendChild(el) : document.getElementById(p).appendChild(el); 
      return el; 
     } 
/* 
The addNode function: 
First argument is the type of element you wish to add. 
Second argument is an object literal containing properties for the element you wish to set. 
Third argument is the parent node to which you wish to append the new element/node. 
*/ 
    </script> 


html 
---- 
<input class="form-control" type="checkbox" id="c1" onclick="msg(event)" name="like"/> 
+0

非常感谢你,但是当我取消选择复选框时,它应该关闭 –

+0

当然你可以添加它? – RamRaider

如果您使用Angularjs,我强烈建议ngDialog。这是我最喜欢的弹出窗口。 你刚才创建的HTML文件将包含弹出的内容和创建对话框的一个实例一旦复选框已被选中你正在尝试(你可以观看使用ngChange价值变动)