Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
WenLiangTseng / click_to_jump_to_specific_tab_page.js
Created July 22, 2013 05:19
讓<a>點到Tab標籤的特定標籤頁
//內部(同一頁)
onclick='$("#tabs").tabs( "select", "tabs-2" )'
//外部(不同頁)
http://www.cglandmark.net/demosite/?page_id=88#thethe-tabs-1-2
//在網址的最後面,加上Tab的ID,例如#thethe-tabs-1-2
@WenLiangTseng
WenLiangTseng / input_numbers_only.js
Created July 22, 2013 05:17
讓HTML的輸入框,只能輸入數字
<input type="text" class="numbersOnly" value="" />
//And:
jQuery('.numbersOnly').keyup(function () {
this.value = this.value.replace(/[^0-9\.]/g,'');
});
@WenLiangTseng
WenLiangTseng / test_jquery_working_or_not.js
Created July 22, 2013 05:16
測試 jQuery 是否有啟動
<script type="text/javascript">
if (typeof jQuery != 'undefined') {
alert('jQuery working!');
} else {
alert('no jQuery, too bad...');
}
</script>
@WenLiangTseng
WenLiangTseng / place_a_popup_div_next_to_mouse_cursor.js
Created July 22, 2013 05:16
把某個彈出DIV放置在滑鼠旁邊
//You can try:
$( "td").click( function(event) {
$("#divId").css( {position:"absolute", top:event.pageY, left: event.pageX});
});
//After additional question was asked in the comment:
$( "td").click( function(event) {
var div = $("#divId");
<a href='javascript:history.go(-1)'>Search Result</a>
@WenLiangTseng
WenLiangTseng / replace_all_string.js
Created July 22, 2013 05:09
取代所有字串
//text版
$('#test').each(function(){
var $this = $(this);
var t = $this.text();
$this.html(t.replace('&lt','<').replace('&gt', '>'));
});
//HTML版
$('#test').each(function(){
var $this = $(this);
var t = $this.html();
@WenLiangTseng
WenLiangTseng / jquery_datapicker_change_date_format_to_save_it_to_MySQL.js
Created July 22, 2013 05:08
jQuery的Datapicker改格式,以存日期到MySQL資料庫
$('#date-picker').datepicker({
dateFormat : 'yy-mm-dd'
});
@WenLiangTseng
WenLiangTseng / select_DOM_by_CSS_and_change_its_CSS.js
Created July 22, 2013 05:07
過濾特定的CSS並且替換樣式
$(".container .component").each(function()
{
$(".container", this).each(function() {
if($(this).css('width') == 'auto')
{
$(this).css('border', '1px solid #f00');
}
});
});
@WenLiangTseng
WenLiangTseng / jquery_disableSelection.js
Created July 22, 2013 05:06
讓滑鼠不能選擇文字(適用於一些 drag and drop 的功能,而非防盜copy)
//In jQuery 1.8, this can be done as follows:
(function($){
$.fn.disableSelection = function() {
return this
.attr('unselectable', 'on')
.css('user-select', 'none')
.on('selectstart', false);
};
})(jQuery);
@WenLiangTseng
WenLiangTseng / jquery_cookie_delete_old_cookie.js
Created July 22, 2013 05:04
jQuery Cookie 為何無法刪除舊cookie的解決方法