select实现option选中事件
程序员文章站
2022-05-24 15:07:49
...
<!DOCTYPE html>
<html lang="en">
<title>伪代码</title>
<head></head>
<body>
<div class="form-group">
<label class="col-md-3 control-label" for="completed">是否已经完成</label>
<div class="col-md-6">
<select name="completed" id="completed" class="form-control" onchange="showAndHide()">
<option value="1" >是</option>
<option value="0" >否</option>
</select>
</div>
</div>
<div class="form-group " id="finishDate" >
<label class="col-md-3 control-label">实际完成时间</label>
<div class="col-md-6">
<input type="text" class="form-control date date-picker" name="finishDate"/>
</div>
</div>
<div class="form-group hidden" id="reasonOfFail">
<label class="col-md-3 control-label">未完成的原因</label>
<div class="col-md-6">
<textarea name="reasonOfFail" rows="3" class="form-control"></textarea>
</div>
</div>
<div class="form-group hidden" id="dueDate">
<label class="col-md-3 control-label">计划整改完成的时间</label>
<div class="col-md-6">
<input type="text" class="form-control date date-picker" name="dueDate"/>
</div>
</div>
<div class="form-group" id="result">
<label class="col-md-3 control-label">整改成果</label>
<div class="col-md-6">
<textarea name="result" rows="3" class="form-control"></textarea>
</div>
</div>
<javascript>
function showAndHide(){
var obj = document.getElementById("completed");
var op = objS.options[obj.selectedIndex].value;
if(op =="1"){
$("#finishDate").removeClass("hidden");
$("#result").removeClass("hidden");
$("#reasonOfFail").addClass("hidden");
$("#dueDate").addClass("hidden");
}else{
$("#finishDate").addClass('hidden');
$("#result").addClass('hidden');
$("#reasonOfFail").removeClass("hidden");
$("#dueDate").removeClass("hidden");
}
}
</javascript>
</body>
</html>
<html lang="en">
<title>伪代码</title>
<head></head>
<body>
<div class="form-group">
<label class="col-md-3 control-label" for="completed">是否已经完成</label>
<div class="col-md-6">
<select name="completed" id="completed" class="form-control" onchange="showAndHide()">
<option value="1" >是</option>
<option value="0" >否</option>
</select>
</div>
</div>
<div class="form-group " id="finishDate" >
<label class="col-md-3 control-label">实际完成时间</label>
<div class="col-md-6">
<input type="text" class="form-control date date-picker" name="finishDate"/>
</div>
</div>
<div class="form-group hidden" id="reasonOfFail">
<label class="col-md-3 control-label">未完成的原因</label>
<div class="col-md-6">
<textarea name="reasonOfFail" rows="3" class="form-control"></textarea>
</div>
</div>
<div class="form-group hidden" id="dueDate">
<label class="col-md-3 control-label">计划整改完成的时间</label>
<div class="col-md-6">
<input type="text" class="form-control date date-picker" name="dueDate"/>
</div>
</div>
<div class="form-group" id="result">
<label class="col-md-3 control-label">整改成果</label>
<div class="col-md-6">
<textarea name="result" rows="3" class="form-control"></textarea>
</div>
</div>
<javascript>
function showAndHide(){
var obj = document.getElementById("completed");
var op = objS.options[obj.selectedIndex].value;
if(op =="1"){
$("#finishDate").removeClass("hidden");
$("#result").removeClass("hidden");
$("#reasonOfFail").addClass("hidden");
$("#dueDate").addClass("hidden");
}else{
$("#finishDate").addClass('hidden');
$("#result").addClass('hidden');
$("#reasonOfFail").removeClass("hidden");
$("#dueDate").removeClass("hidden");
}
}
</javascript>
</body>
</html>
推荐阅读