Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
WenLiangTseng / document_ready_function.js
Created July 22, 2013 02:27
JavaScript內嵌+Document.Ready.Function
<script type="text/javascript">
jQuery('document').ready(function($) {
// Handler for .ready() called.
});
</script>
@WenLiangTseng
WenLiangTseng / javascript_placement.js
Created July 22, 2013 02:30
JavaScript 和 CSS引用基本格式
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<link type="text/css" rel="stylesheet" media="all" href="http://domain.com/css/style.css" />
@WenLiangTseng
WenLiangTseng / jQuery_ajax_example.js
Created July 22, 2013 02:30
jQuery AJAX 比較好的寫法
// variable to hold request
var request;
// bind to the submit event of our form
$("#foo").submit(function(event){
// abort any pending request
if (request) {
request.abort();
}
// setup some local variables
var $form = $(this);
@WenLiangTseng
WenLiangTseng / jquery_cookie_delete_old_cookie.js
Created July 22, 2013 05:04
jQuery Cookie 為何無法刪除舊cookie的解決方法
@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 / 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_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 / 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();
<a href='javascript:history.go(-1)'>Search Result</a>
@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");