[英]jquery retrieve text next to radio (no label tag) — have working on click but how to work on load?
http://jsfiddle.net/acts7/wcL7c/9/所以我有這段代碼。
(在您建議之前……不,我不能在文本周圍包裹標簽。我無權訪問它)
當用戶單擊單選按鈕或單選按鈕時,或者當他們專注於單選按鈕時,我可以立即檢索該文本。 換句話說,當用戶采取行動時。
然而; 由於我正在努力為使用屏幕閱讀器的用戶提供更好的生活,因此需要在單擊該文本之前先應用此文本。
如何遍歷整個表單,立即在每個輸入字段之后抓取文本,並將其分配給單選按鈕上的title屬性?
問題:我如何獲取該文本...我已經知道如何將其分配給title屬性
這項工作
$("input[type=radio]").focus(function(e) {
var radioText = e.currentTarget.nextSibling.data
//alert(radioText);
$(this).attr('title', radioText);
});
這不
$("input[type=radio]").each(function() {
var radioText = $(this).currentTarget.nextSibling.data
alert(radioText);
});
在事件處理程序中,事件對象的currentTarget
屬性是元素。 在循環中, this
是元素,因此只需使用它代替currentTarget
:
$("input[type=radio]").each(function() {
$(this).attr('title', this.nextSibling.data);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.