当我单击链接并想添加无法正常运行的课程时
我想做(div modal)
代码php / html
<?php if(isset($_GET['ido']) )
{
?>
<div id ="modal" class="modal" style="background: blue; width: 100%;
height: 180%">
<div class="modal2" >
</div>
</div>
<?php
}
?>
<div id="no" class="no" style="width: 100%;height: 300%;background: #000">
<div class="nolink" style="width: 50%;height: 50%;margin: 0 auto ; background: #fff">
<span>
<a href="?ido=22" id="link">link </a>
</span>
</div>
</div>
代码javascript
<script type="text/javascript">
document.getElementById('link').onclick = function(){
document.getElementById('modal').classList.add('new') ;
};
</script>
当我单击链接并想添加无法正常运行的课程时
我想做(div modal)
最佳答案
如果要在单击时添加新类,则应删除php条件并在onClick函数中添加“ return false”
像这样:https://codepen.io/tuzov/pen/OQWJzB
document.getElementById('link').onclick = function(){
document.getElementById('modal').classList.add('new') ;
return false;
};
.modal {
display:none;
}
.modal.new {
display:block;
}
<div id ="modal" class="modal" style="background: blue; width: 100%;
height: 180%">
<div class="modal2" >
123
</div>
</div>
<div id="no" class="no" style="width: 100%;height: 300%;background: #000">
<div class="nolink" style="width: 50%;height: 50%;margin: 0 auto ; background: #fff">
<span>
<a href="?ido=22" id="link">link </a>
</span>
</div>
</div>