我有一段代碼,當我把它放在頁面上時工作正常,當我把腳本放在單獨的文件中時,它沒有工作。當JavaScript把它放在單獨的文件中時,Jquery點擊事件沒有綁定<a>標記
SCRIPT
$(document).ready(function() {
$('[id*=SearchLocator]').on("keydown", function (event) {
if (event.keyCode == 13) {
$('#SearchStoreLocator').trigger("click");
}
});
$('#SearchStoreLocator').on("click", function (e) {
e.preventDefault();
alert("hello");
});
});
HTML
<asp:TextBox ID="SearchLocator" runat="server" ValidationGroup="PostCodeSearchValidation"
ToolTip="Enter an address" MaxLength="200" CssClass="AddressSearch" />
<a id="SearchStoreLocator">Find</a>.
渲染HTML
<input name="ctl00$PageContent$Survey$ctl06$SearchLocator" type="text" maxlength="200" id="ctl00_PageContent_Survey_ctl06_SearchLocator" title="Enter an address" class="AddressSearch" placeholder="Enter a location" autocomplete="off">
<a id="SearchStoreLocator">Find</a>
我不知道怎麼回事就在這裏...只是hello alert
時不顯示我的點擊鏈接(當我把腳本放在一個單獨的文件中)
jQuery的版本
jquery-1.8.3.min.js
jquery-1.9.1.min.js
both are loaded on the page, BUT other things are working fine except only this <a> tag.
NOTE: i am loading jquery twice as there are some things that are not supported by jquery-1.8.3
編輯
after removing jquery-1.8.3.min.js still not working...
我認爲你缺少DOM準備包裝。準備好DOM腳本。 – PSL
你爲什麼要加載jquery兩次? – Smeegs
爲什麼你使用兩個版本的jQuery和DOM準備丟失? –