function myFunction(e) {
	var currentTab = $(e).data("target");

	$(currentTab).is(':visible') && $(currentTab).hide('slow') || $(currentTab).show('slow').siblings().hide('slow');
	if ($(currentTab).is(":hidden")){
		$(currentTab).children('input').attr("name", 'filterMode');
		$(currentTab).children('input').attr('value', currentTab);
		$(currentTab).children('div').children('input:first').attr("name", 'filterBegin');
		$(currentTab).children('div').children('input:last').attr("name", 'filterEnd');
	}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="panel panel-primary searchPanel">
	<ul class="nav nav-list panel-tabs filterButtons">
		<li>
			<button class="btn btn-arya btn-primary" type="button" data-target="#kararNo" data-toggle="tab"
					onclick="myFunction(this)">Karar No İle
			</button>
		</li>
	</ul>
	<div class="panel-body">
		<div class="tab-content">
			<div class="tab-pane" id="kararNo">
				<input type="hidden" class="form-control filterInputs" id="searchInput0" placeholder="Karar No">
				<div class="input col-sm-5">
					<input type="text" class="form-control filterInputs" id="searchInput1" placeholder="Karar No">
				</div>
			</div>
		</div>
	</div>
</div>

Estas entradas se abren con el primer clic, el segundo clic se cierra.

Quiero eliminar cuando cierro los atributos agregados cuando abro. Puedes ayudarme por favor ?

0
Ömer 16 oct. 2018 a las 13:56

2 respuestas

La mejor respuesta
function myFunction(e) {
    var currentTab = $(e).data("target");
    var filters = ['filterMode', 'filterBegin','filterEnd'];

    if($(currentTab).is(':visible')){
        $(currentTab).children('input').removeAttr('value');
        $(currentTab).find('input').map(function(index,input){
            $(input).removeAttr("name");
        });
        $(currentTab).siblings().find('input').map(function(index,input){
            $(input).removeAttr("name");
        });
        $(currentTab).hide('slow');

    }else{
        $(currentTab).children('input').attr('value', currentTab);
        $(currentTab).find('input').map(function(index,input){
            $(input).attr("name", filters[index]);
        });

        $(currentTab).siblings().find('input').map(function(index,input){
            $(input).removeAttr("name");
        });
        $(currentTab).show('slow').siblings().hide('slow');

    }
}

Solución de mi pregunta, eso es todo. Muchas gracias

1
Ömer 17 oct. 2018 a las 08:29
function myFunction(e) {
    var currentTab = $(e).data("target");
// check element visible
 if($('#kararNo:visible').length == 0){
     console.log("visible");
  }else{
    console.log("hidden");
  }
  
  //end element visiblity check
    $(currentTab).is(':visible') && $(currentTab).hide('slow') || $(currentTab).show('slow').siblings().hide('slow');
    if ($(currentTab).is(":hidden")){
    console.log("hidden");
        $(currentTab).children('input').attr("name", 'filterMode');
        $(currentTab).children('input').attr('value', currentTab);
        $(currentTab).children('div').children('input:first').attr("name", 'filterBegin');
        $(currentTab).children('div').children('input:last').attr("name", 'filterEnd');
    }
}
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  var target = $(e.target).attr("href") // activated tab
  alert(target);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.bundle.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="panel panel-primary searchPanel">
    <ul class="nav nav-list panel-tabs filterButtons">
        <li>
            <button class="btn btn-arya btn-primary" type="button" data-target="#kararNo" data-toggle="tab"
                    onclick="myFunction(this)">Karar No İle
            </button>
        </li>
    </ul>
    <div class="panel-body">
        <div class="tab-content">
            <div class="tab-pane" id="kararNo">
                <input type="hidden" class="form-control filterInputs" id="searchInput0" placeholder="Karar No">
                <div class="input col-sm-5">
                    <input type="text" class="form-control filterInputs" id="searchInput1" placeholder="Karar No">
                </div>
            </div>
        </div>
    </div>
</div>

Simplemente use su identificación conocida para verificar la visibilidad de la siguiente manera.

if($('#kararNo:visible').length == 0){
     console.log("visible");
  }else{
    console.log("hidden");
  }
0
Sumesh TG 16 oct. 2018 a las 11:16