Skip to content

Instantly share code, notes, and snippets.

@firstfu
Last active March 1, 2018 04:28
Show Gist options
  • Save firstfu/aac9eaa28eadd6c48449d0e5e892ff8f to your computer and use it in GitHub Desktop.
Save firstfu/aac9eaa28eadd6c48449d0e5e892ff8f to your computer and use it in GitHub Desktop.
##arrary選擇
var contry = $("div h5").eq(4).text();
##input - label选择
$("label[for=email]")
##select/option選取
$('#selectBox option[value=C]').prop('selected', true);
##選取裡面有name...等元素用的方式
$("input[name=title]").val(_s_title)
##取得選取的元素屬於td第幾行第幾列(最簡易的方法)
var _index = $('.test.test1').index($(this));
##取得選取的元素屬於td第幾行第幾列(麻煩的方法)
$('table tr td').click(function(){
alert( $(this).parent().parent().find("tr").index($(this).parent()[0]));//第几行
alert($(this).index());//第几列
}
);
##找到目標URL並替換url
$(".art-hmenu li a[href$='/test']").attr('href', '/test')
##找到目標URL並替換文字
$(".test a[href$='/test']").text('test');
##在選取的元素之前加入html
$('input:radio[name="test"]:first').parent().parent().prepend('<font color=“#FFFFFF”>*</font>');
##input:radio必填
$('input:radio[name="test"]').attr('required', true);
##input:text必填
$('input:text[name="test"]').attr('required', true);
##判斷Radio是否選取
if ($('input#type-home:checked').length >= 1) {
}
##取得radio array index
var radios = $('input:radio[name="test"]');
radios.click(function(event) {
var choiceIndex = radios.index($(this));
});
##改變下拉式選單select的某項的值
$("#test").eq(0).text("-test-");
##改變CSS樣式
$('.art-postheader').css('font-size', '90px');
##input:select下拉式選單
$('input.down_menu').attr('checked', true);
$('input.down_menu:checkbox:checked').length
$('input.down_menu:checkbox:checked').serializeArray()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment