当我选择“更新”时,我试图隐藏其他html元素。选项然后当前公司,当前的ctc和通知元素将隐藏。我不知道怎么做。请帮帮我。
见下面的代码:
<div class="form-group">
<div class="col-xs-6">
Experience:
<select name="experience" class="form-control" id="exp" value="<?php echo $experience; ?>" required>
<option></option>
<option>fresher</option>
<option>0-1 years</option>
<option>1-3 years</option>
<option>4-5 years</option>
<option>5+ years</option>
</select>
<div class="error"><?php echo form_error("experience");?></div>
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
current_company Name:
<input type="text" name="ccn" class="form-control" id="ccmp" value="<?php echo set_value('ccn'); ?>" placeholder="current company name" required>
<div class="error"><?php echo form_error("ccn");?></div>
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
Notice period:
<select name="notice" class="form-control" id="notice" value="<?php echo $notice_period; ?>" placeholder="notice period in months" required>
<option></option>
<option>10-30 days</option>
<option>1 month</option>
<option>2 months</option>
<option>3 months</option>
</select>
<div class="error"><?php echo form_error("notice");?></div>
<br>
current CTC:
<input type="text" name="ctc" class="form-control" id="ctc" value="<?php echo set_value('ctc'); ?>" placeholder="currenty ctc" required>
<div class="error"><?php echo form_error("ctc");?></div>
</div>
</div>
我正在尝试这个jquery
$(documnet).ready(function{
$("#exp:selected").val('fresher').hide($("#ccmp"));
});
答案 0 :(得分:1)
您需要使用change event
并select
name=experience
或selected text
hide
为您的show
撰写closest
ccmp
notice
和$(document).ready(function() {
$('select[name="experience"]').on('change', function() {
if($(this).find("option:selected").text()=="fresher") //check if option selected is fresher
$('#ccmp, select[name="notice"]').closest('.form-group').hide();//hide the parents
else
$('#ccmp, select[name="notice"]').closest('.form-group').show();//show the parents
})
})
元素的父级
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group">
<div class="col-xs-6">
Experience:
<select name="experience" class="form-control" id="exp" value="<?php echo $experience; ?>" required>
<option></option>
<option>fresher</option>
<option>0-1 years</option>
<option>1-3 years</option>
<option>4-5 years</option>
<option>5+ years</option>
</select>
<div class="error">
<?php echo form_error( "experience");?>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
current_company Name:
<input type="text" name="ccn" class="form-control" id="ccmp" value="<?php echo set_value('ccn'); ?>" placeholder="current company name" required>
<div class="error">
<?php echo form_error( "ccn");?>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-6">
Notice period:
<select name="notice" class="form-control" id="notice" value="<?php echo $notice_period; ?>" placeholder="notice period in months" required>
<option></option>
<option>10-30 days</option>
<option>1 month</option>
<option>2 months</option>
<option>3 months</option>
</select>
<div class="error">
<?php echo form_error( "notice");?>
</div>
<br>current CTC:
<input type="text" name="ctc" class="form-control" id="ctc" value="<?php echo set_value('ctc'); ?>" placeholder="currenty ctc" required>
<div class="error">
<?php echo form_error( "ctc");?>
</div>
</div>
</div>
{{1}}
答案 1 :(得分:0)
如果所选选项为“更新”,则会隐藏 String url = "http://google.com/";
i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
元素
#ccmp
答案 2 :(得分:0)
我认为您在脚本级别出错了。您输入“ $(documnet).ready ”而不是“ $(document).ready ”。尝试更改它并运行代码。
答案 3 :(得分:0)
您可以在选择下拉列表中添加change
事件,然后检查其val
。隐藏适用于
$(id).hide()
不是.hide(el)
,所以你需要交换那个
$(function() {
$("#exp").change(function() {
if ($("#exp").val() == "fresher") {
$("#cmp").hide();
}
})
});
答案 4 :(得分:0)
添加class =&#34; hideClass&#34;要隐藏的所有元素,请尝试使用此代码。
$(document).on('change','#exp',function(e){
var text = $('#exp').find(":selected").text();
if(text=='fresher'){
$('.hideClass').hide();
}
});