本文介绍了javascript getElementById开头为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想选择 div 以 * 开头,从 到 display:hidden
I want to select div start with * to change it from display: block to display:hidden
function select_to_text(a) { var as = '#' + a; var aa = $(as).val(); if (aa == "0") {} else { //var $eles = $(":*[name^='personal_family_type_']").css("background-color","yellow"); document.getElementById(a + "_" + aa + "_block").style.display = 'block'; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group"> <label for="personal_family_type" class="control-label col-sm-2">type</label> <div class="col-sm-10"> <select size="1" id="personal_family_type" name="personal_family_type" class="form-control btn btn-primary" onchange="select_to_text('personal_family_type')"> <option value="0">----</option> <option value="wife">Wife</option> <option value="husband">Husband</option> <option value="son">Son</option> <option value="all">Show all</option> </select> <div id="personal_family_type_wife_block" style="display :none"> wife </div> <div id="personal_family_type_husband_block" style="display :none"> husband </div> <div id="personal_family_type_son_block" style="display :none"> son </div> </div> </div>
推荐答案
这里是一个在jQuery中完成的解决方案。从您的html元素中移除onclick。
Here is a solution done in jQuery. Remove the onclick from your html element.
$( document ).ready(function() { $('#personal_family_type').on('click', function() { $("#"+this.id + "_" + this.value + "_block").toggle(); }); });
这里是
这篇关于javascript getElementById开头为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!