我有一個(gè)包含 3 個(gè)不同部分的表單,我還有一些哈希鏈接(#one、#two、#third)可轉(zhuǎn)到表單頁(yè)面,但會(huì)根據(jù)哈希在頁(yè)面加載時(shí)顯示相應(yīng)的表單部分。我讓它工作,表單視圖根據(jù)哈希 URL 進(jìn)行更新,但實(shí)際表單沒(méi)有更新以收集數(shù)據(jù)和驗(yàn)證。我需要發(fā)生的是實(shí)際的單選按鈕更改,就像單擊它一樣。因此,如果 url 是 www......com/#two,則相應(yīng)的單選按鈕 2 將被單擊并激活,就像當(dāng)用戶(hù)被發(fā)送到帶有頁(yè)面鏈接/哈希的頁(yè)面時(shí)在表單上手動(dòng)單擊它一樣。HTML: <div class="register_input-container register_input-container--checkbox all role-checkbox"> <div class="register_checkbox_label-row row"> <div class="register_checkbox_label-container col"> <label tabindex="0" for="register_one" class="form_checkbox_label form_checkbox_label--role selected-role" id="one" data-role="one"> Label One </label> </div> <div class="register_checkbox_label-container col"> <label tabindex="0" for="register_two" class="form_checkbox_label form_checkbox_label--role" id="two" data-role=two" data-offset="0"> Label Two </label> </div> <div class="register_checkbox_label-container col"> <label tabindex="0" for="register_three" class="form_checkbox_label form_checkbox_label--role " id="three" data-role="three"> Label Three </label> </div> </div> <input type="radio" id="register_one" name="role"> <input type="radio" id="register_two" name="role"> <input type="radio" id="register_three" name="role"></div>
1 回答

慕雪6442864
TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
不使用,而是在按鈕上toggleFormView模擬 a :click()
document.addEventListener("load", function() {
var hash = window.location.hash;
if (hash) $(hash).click(); // For instance: $("#two").click()
});
- 1 回答
- 0 關(guān)注
- 140 瀏覽
添加回答
舉報(bào)
0/150
提交
取消