大家好,当用户选择一个选项时,我正在尝试做的每一件事,都会出现另一个选项。是的,我做到了,但是当用户选择其他选项时,我想显示文本但它不起作用这是我的代码:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script></script>
<script type="text/javascript">
$(document).ready(function() {
$(".select-box").change(function() {
if ($(".select-box option[value='3']").attr('selected')) {
document.getElementById("demo").innerHTML="<select class='select-box'><option value='4'>a</option><option value='5'>b</option></select>";
if ($(".select-box option[value='5']").attr('selected')) {
document.write("Hello")
}
}
});
});
</script>
</head>
<body>
<select class="select-box">
<option>Select an option</option>
<option value="1">no alert</option>
<option value="2">no alert too</option>
<option value="3">alert</option>
</select>
<p></br>
<div id="demo"></div>
</body>
</html>