我需要將單選按鈕及其旁邊的文字包裝在標籤中,以方便用戶使用。在元素旁邊選擇文字(幾乎)
前幾天我有一個類似的問題,我有一個複選框,並在我有一個span元素後立即。我可以包裝這兩個元素。
我有這樣的HTML:
<span class="Attribute">
<input type="radio" name="vMONHRDREM" value="S">
<script type="text/javascript">gx.dom.setAttribute("vMONHRDREM","gxoch0","if(!(gx.evt.jsEvent(this))) return false;");</script>
Ativado
<input type="radio" name="vMONHRDREM" value="N">
<script type="text/javascript">gx.dom.setAttribute("vMONHRDREM","gxoch0","if(!(gx.evt.jsEvent(this))) return false;");</script>
Desativado
</span>
不幸的是,我不能,因爲我用的是生成網頁的工具更改HTML結構。
我試圖做這樣的事情:
$("input[type=radio]").each(function(){
alert($(this).next().next().text());
});
但它不工作。它不會返回任何東西。如果我更改爲$(this).next().text()
,我會看到腳本文本。
更新: 最終解決方案。
$('.Attribute input[type="radio"]').each(function() {
$($(this).next('script')[0].nextSibling).wrap("<span />");
$(this).addBack().add($(this).next('script')[0].nextSibling).wrapAll('<label></label>')
});
謝謝你們
謝謝你的男人。正是我的意思!謝謝兩位! – lcssanches 2013-04-10 13:26:21