Javascript 动态更改标签和占位符取决于加载的html
我在后端使用带有laravel的jquery。我有两个php刀片上加载的搜索栏。我想占位符和标签的动态变化取决于加载的php刀片文件。这就是它现在的样子,它只显示第一个标签和占位符,即使在id中也不存在,它显示第一个标签和占位符 HTML/BLADE.PHPJavascript 动态更改标签和占位符取决于加载的html,javascript,php,jquery,html,laravel,Javascript,Php,Jquery,Html,Laravel,我在后端使用带有laravel的jquery。我有两个php刀片上加载的搜索栏。我想占位符和标签的动态变化取决于加载的php刀片文件。这就是它现在的样子,它只显示第一个标签和占位符,即使在id中也不存在,它显示第一个标签和占位符 HTML/BLADE.PHP <div class="container"> <div class="row"> <div class="show-hide-section"> <
<div class="container">
<div class="row">
<div class="show-hide-section">
<button class="btn btn-success show-hide-search-bar">Pokaż wyszukiwarkę</button>
</div>
<div class="col-xs-12 col-md-12">
<div class="searcher-section" style="display: none">
<div class="show-hide-searcher">
<div class="input-section">
<div class="label-input-searcher">
<label for="" class="searcher-label" id="label-searchbar"></label>
<input type="text" placeholder="" class="searcher-input form-control" id="input-searchbar" />
<div class="null-data" style="display: none;">Wprowadź poprawne dane</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
使用jQuery对象的属性检查元素是否存在$(选择器)
将返回一个永远不会为null的jQuery对象
if ($('#agents').length > 0) {
$('#label-searchbar').html('Imię, Nazwisko, Adres email');
$('#input-searchbar').attr('placeholder','Podaj imię, nazwisko lub adres email');
} else if ($('#company').length > 0) {
$('#label-searchbar').html('Nazwa biura');
$('#input-searchbar').attr('placeholder','Podaj nazwę biura');
}
if ($('#agents').length > 0) {
$('#label-searchbar').html('Imię, Nazwisko, Adres email');
$('#input-searchbar').attr('placeholder','Podaj imię, nazwisko lub adres email');
} else if ($('#company').length > 0) {
$('#label-searchbar').html('Nazwa biura');
$('#input-searchbar').attr('placeholder','Podaj nazwę biura');
}