我使用'之前'選擇器爲'我'單選按鈕'標籤'標籤樣式。 我對標籤使用'click'事件來使所有瀏覽器的點擊都可以點擊(chrome不支持點擊之前/之後的元素)。 有一個現有的腳本,它將顯示/隱藏單擊單選按鈕上的某些元素。相同事件的兩個單獨處理程序
我試圖做
我寫上「點擊」標貼的事件的腳本。現有的顯示/隱藏功能無法正常工作,因爲我試圖在點擊標籤時啓動無線點擊。
我需要什麼
我需要編寫一個腳本,應該不會影響現有的腳本(顯示/隱藏),它應該在所有的瀏覽器。
我不能做什麼
- 我不能簡單地通過給ID和屬性,完成它。 :(
- 我無法自定義現有的腳本。
我想我能做到
- 我可以修改HTML/CSS通過任何其他方式來設計我的收音機。但是,有很多地方做的改變。:(
- 使用「變」事件而不是「點擊」的顯示/隱藏的div。
代碼示例
/*what I'm trying...*/
$(document).ready(function(){
$('input[type="radio"]+label').on('click',function(){
$(this).prev().click();
});
});
/*existing script*/
$('input[name="fieldname"]').click(function(){
if($('#fieldid').is(':checked')){
$('#divid').show();
$('#divid1').hide();
} else if($('#fieldid1').is(':checked')){
$('#divid1').show();
$('#divid').hide();
}
});
/*existing script*/
.divs, input[type="radio"]{display:none;}
input[type="radio"]+label::before{
content:" ";
display:inline-block;
position:relative;
left:0;
top:0;
background:red;
height:10px;
width:10px;
border-radius:50%;
}
input[type="radio"]:checked+label::before{
background:blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="radio" name="fieldname" id="fieldid" class="fieldclass" />
<label>show textfield</label>
<input type="radio" name="fieldname" id="fieldid1" class="fieldclass" />
<label>show button</label>
<div id="divid" class="divs"><input type="text" size="30"></div>
<div id="divid1" class="divs"><input type="submit" value="button"></div>
</form>
感謝您的回答:) – Anand
是的,我可以將新的腳本後的老版本 – Anand
歡迎@Anand ...好的,這真是太棒了:) – Souvik