我爲難我的查詢.click()不起作用而難過。我試圖在轉到下一頁之前更改a元素上的href標記。爲什麼jQuery的.click()wouldent目標的標籤?
,這裏是我的jQuery
$('.individualFormSections').click(function() {
var formSectionTitle = $(this).siblings('div').text(); // gets section title that was clicked
console.log(formSectionTitle);
assetConfigIdForURL = assetConfigIdForURL.replace(/\s+/g,'-');
woTypeCodeForURL = woTypeCodeForURL.replace(/\s+/g,'-');
woMaintTypeCode = woMaintTypeCode.replace(/\s+/g,'-');
formSectionTitle = formSectionTitle.replace(/\s+/g,'-');
// Change href dynamically to set url parameters
$(this).attr("href",'airSystem.html?insp_asset_config_id='+assetConfigIdForURL+'&wo_type_code='+woTypeCodeForURL+'&wo_maint_type_code='+woMaintTypeCode+'&formSection='+formSectionTitle+'&wo_id='+woIdForURL+'');
});
下面是HTML
<a class="individualFormSections" href="">
<img class="bus-form-img" src="pull-up.jpg" alt="Trolltunga Norway">
</a>
<div class="desc" id="bodyDamageDesc">AirSystem</div>
我也試着做一個簡單的警告和它甚至不是針對一個標籤。我的JavaScript鏈接設置正確。
有一點背景,html是從以前的javascript函數動態生成的。當我使用Chrome開發人員工具時,所有的html顯示都很好。任何想法可能會導致這種情況?
它的工作,但標籤首先處理的點擊。你需要在你的點擊函數中使用preventDefault() – Cruiser
[* *動態生成*](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements/27373951) –
這是一塊我需要但沒有解決我的問題。可能還有另一個因素,爲什麼它不工作。將回到這個 – plgelso