有獲得點擊DIV ID 一個FUNC需要給下一個FUNC這個ID代替 「#dropdown1」如何獲得DIV ID,並將其設置爲anoher FUNC
$(function() {
$('.drop-down-input').click(function() {
$elementid = this.id;
$elementid= "#" + elementid;
});
console.log($elementid);
$("#dropdown1").click(function() {
$("#dropdown1 .dropdown-list").show();
});
$("#dropdown1 .dropdown-list li").on('click', function(e) {
e.stopPropagation();
$("#dropdown1 .dropdown-list").hide().siblings().val($(this).html());
});
});
HTML:
<div id="dropdown1" class="styled-input-container drop-down-input">
<input id="simple_2" class="drop-down-select" placeholder="input text" type="text">
<ul class="dropdown-list">
<li>eeee</li>
<li>xxxx</li>
<li>xxxx</li>
<li>xsssxxx</li>
</ul>
</div>
想法是我可以在另一個地方再次使用此代碼。 for examle use 2 dropdowns with different ID
使全局變量 – Mahi
你想實現什麼?這似乎是一個不好的做法。 – Mihailo
未捕獲的ReferenceError:在單擊任何內容後沒有定義elementid(...) –