귀하의 자바 스크립트 코드는 좋아요. 약간 결함이있는 유일한 것은 if 문이지만 어쨌든 그것을 트리거해야합니다. 이 검사가 효과가 있습니까?
var firstName = prompt('Please enter your first name');
var secondName = prompt('Please enter your second name');
if (firstName != '' && secondName != ''){
var x = document.getElementById('standard');
x.style.display = "block";
}
else{
alert('please enter first and second name');
}
#standard { display: none; }
<html>
<head></head>
<body>
<h1 id="heading">Heading</h1>
<div id="standard">
<input type="radio" name="standard">1
<input type="radio" name="standard">2
</div>
</body>
</html>
지금, 당신의 진짜 문제는 당신이 그것을 숨기기를 해제하려고 할 때 HTML/DOM 요소가로드되지 않는 것입니다. Chrome 콘솔을 확인하여 확인할 수 있습니다. 그러면 정의되지 않은 속성 스타일을 설정할 수 없다는 오류가 표시됩니다.
1) 신체의 끝 부분에 app.js 장소 :
를 해결하려면, 당신은 두 가지 옵션이 있습니다.
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1 id="heading">Heading</h1>
<div id="standard">
<input type="radio" name="standard">1
<input type="radio" name="standard">2
</div>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
2) 그렇지 않으면 윈도우 부하에 JS 코드를 넣을 수 있습니다 :
window.onload = function() {
var firstName = prompt('Please enter your first name');
var secondName = prompt('Please enter your second name');
if (firstName != '' && secondName != ''){
var x = document.getElementById('standard');
x.style.display = "block";
}
else{
alert('please enter first and second name');
}
};
이것은 당신의 코드가 작동해야합니다. 후자의 방법이 바람직하다.
는 CSS를 코딩 .. –
#standard을 {포함 \t 디스플레이 : 없음; } – srs
[브라우저 콘솔 (dev tools)] (http://webmasters.stackexchange.com/q/8525) ('F12')을 클릭하고 오류를 읽습니다. – Xufox