讓container的圖片讀取完畢再做動作
$(function() {
$('#container').imagesLoaded(function() {
$('#container').masonry({
itemSelector : '.item',
columnWidth : 10
});
});
});
http://stackoverflow.com/questions/7476649/jquery-masonry-breaksstacks-images-in-chrome-safari-but-only-on-first-load
jQuery ~ move Table tr
$(document).ready(function(){
$(".up,.down").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
row.insertBefore(row.prev());
} else {
row.insertAfter(row.next());
}
});
});
reference
http://stackoverflow.com/questions/1569889/jquery-move-table-row
$(".up,.down").click(function(){
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
row.insertBefore(row.prev());
} else {
row.insertAfter(row.next());
}
});
});
reference
http://stackoverflow.com/questions/1569889/jquery-move-table-row
jQuery ~ Datepicker change language
download js
http://logicss.googlecode.com/svn-history/r41/trunk/media/jquery/jquery.ui.i18n.all.min.js
$.datepicker.setDefaults($.datepicker.regional["zh-TW"])
http://logicss.googlecode.com/svn-history/r41/trunk/media/jquery/jquery.ui.i18n.all.min.js
$.datepicker.setDefaults($.datepicker.regional["zh-TW"])
jQuery ~ move element
$("#source").appendTo("#destination");
reference
http://stackoverflow.com/questions/1279957/how-to-move-an-element-into-another-element
reference
http://stackoverflow.com/questions/1279957/how-to-move-an-element-into-another-element
解決Discuz和jQuery的衝突~
我是用人家的解決方法1
将jquery.js在common.js之前载入,不然jquery的$()函数会覆盖common.js的$()函数;然后用到jQuery的$()函数的地方都用jQuery()代替。
不過我是用$jq代替= =
var $jq = jQuery;
http://witmax.cn/discuz-jquery-conflict.html
将jquery.js在common.js之前载入,不然jquery的$()函数会覆盖common.js的$()函数;然后用到jQuery的$()函数的地方都用jQuery()代替。
不過我是用$jq代替= =
var $jq = jQuery;
http://witmax.cn/discuz-jquery-conflict.html
jQuery Flot ~ set Label example
var d1 = [];
d1.push([1, 1234]);
d1.push([2, 5678]);
var stack = 0, bars = true, lines = false, steps = false;
$.plot($("#statisticsGraph"), [d1], {
series: {
lines: { show: lines, fill: true },
bars: { show: bars, barWidth: 0.8 }
}, xaxis: {
ticks: [[1, 'out hospital'], [2, 'in hospital']]
}
});reference
http://stackoverflow.com/questions/459947/how-do-i-control-the-tick-label-size-in-flot
jQuery Flot ~ Invalid dimensions for plot
Invalid dimensions for plot, width = 893, height = 0
假如要用jQuery Flot 產生圖表
出現這問題是因為
沒有設定到指定畫圖表物件的高跟寬
加上css設定下就OK~
假如要用jQuery Flot 產生圖表
出現這問題是因為
沒有設定到指定畫圖表物件的高跟寬
加上css設定下就OK~
#statisticsResult{
height:300px;
width:300px;
}
height:300px;
width:300px;
}
jQuery ~ reset form
不能這樣寫....
要這樣寫XD
reference
http://simple.procoding.net/2008/11/22/how-to-reset-form-with-jquery/
$('#form').reset();
要這樣寫XD
$('#form').each(function(){
this.reset();
});
this.reset();
});
reference
http://simple.procoding.net/2008/11/22/how-to-reset-form-with-jquery/
Javascript ~ calulate table total by jQuery
這是一個關於用javascript計算表格的總total的做法
其實PHP也可以做~~~~只是我懶得又在PHP設定每個欄位總total的變數~~然後又在那邊++++++
最後再顯示出來
所以我改用javascript來做~~
這段程式要在table已經產生出來才run
像我這表格是透過AJAX抓出來放網頁上~~~~所以要在result出來才做
Javascript
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
HTML
----------------------------------------------------------------------------------------------------
其實PHP也可以做~~~~只是我懶得又在PHP設定每個欄位總total的變數~~然後又在那邊++++++
最後再顯示出來
所以我改用javascript來做~~
這段程式要在table已經產生出來才run
像我這表格是透過AJAX抓出來放網頁上~~~~所以要在result出來才做
Javascript
----------------------------------------------------------------------------------------------------
var x = Object();
$('#overtimeList tr:gt(0)').each(function(){
for(var i = 2; i < 17; i++){
if(isNaN(x[i])){
x[i] = 0;
}
var value = parseFloat($(this).find('td:eq('+i+')').html());
if(!isNaN(value)){
x[i] += value;
}
}
})
for(var i = 2; i < 17; i++){
$('#overtimeList tr.last td:eq('+i+')').html(x[i]);
}
$('#overtimeList tr:gt(0)').each(function(){
for(var i = 2; i < 17; i++){
if(isNaN(x[i])){
x[i] = 0;
}
var value = parseFloat($(this).find('td:eq('+i+')').html());
if(!isNaN(value)){
x[i] += value;
}
}
})
for(var i = 2; i < 17; i++){
$('#overtimeList tr.last td:eq('+i+')').html(x[i]);
}
----------------------------------------------------------------------------------------------------
HTML
----------------------------------------------------------------------------------------------------
<table class="overtimeList" cellspacing="0" id="overtimeList">
<tr class="last">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<tr class="last">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
PHP and jQuery Autocomplete example
HTML and Javascript
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
PHP
--------------------------------------------------------------------------------------------------------------
reference
http://www.pengoworks.com/workshop/jquery/autocomplete.htm
--------------------------------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
function lookupAjax(){
var oSuggest = $("#CityAjax")[0].autocompleter;
oSuggest.findValue();
return false;
}
$(document).ready(function() {
$("#CityAjax").autocomplete(
"getData.php",
{
delay:10,
minChars:2,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:true
}
);
});
function findValue(li) {
if( li == null ) return alert("No match!");
// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];
// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;
//alert("The value you selected was: " + sValue);
}
function formatItem(row) {
return row[0] + " (id: " + row[1] + ")";
}
function selectItem(li) {
findValue(li);
}
</script>
</head>
<body>
<input type="text" id="CityAjax" value="" style="width: 200px;" />
<input type="button" value="Get Value" onclick="lookupAjax();" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type='text/javascript' src='jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script type="text/javascript">
function lookupAjax(){
var oSuggest = $("#CityAjax")[0].autocompleter;
oSuggest.findValue();
return false;
}
$(document).ready(function() {
$("#CityAjax").autocomplete(
"getData.php",
{
delay:10,
minChars:2,
matchSubset:1,
matchContains:1,
cacheLength:10,
onItemSelect:selectItem,
onFindValue:findValue,
formatItem:formatItem,
autoFill:true
}
);
});
function findValue(li) {
if( li == null ) return alert("No match!");
// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];
// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;
//alert("The value you selected was: " + sValue);
}
function formatItem(row) {
return row[0] + " (id: " + row[1] + ")";
}
function selectItem(li) {
findValue(li);
}
</script>
</head>
<body>
<input type="text" id="CityAjax" value="" style="width: 200px;" />
<input type="button" value="Get Value" onclick="lookupAjax();" />
</body>
</html>
--------------------------------------------------------------------------------------------------------------
PHP
--------------------------------------------------------------------------------------------------------------
$name = strtolower($_GET['q']).'%';
$sql = "SELECT * FROM clubs WHERE lower(name) LIKE ".$name." ORDER BY name ASC";
$r = db_query($sql);
while($x = db_fetch($r)){
print $x['name']."\n";
}
--------------------------------------------------------------------------------------------------------------$sql = "SELECT * FROM clubs WHERE lower(name) LIKE ".$name." ORDER BY name ASC";
$r = db_query($sql);
while($x = db_fetch($r)){
print $x['name']."\n";
}
reference
http://www.pengoworks.com/workshop/jquery/autocomplete.htm
jQuery ~ get select box select index
取下拉選單的selectedIndex~
source
http://blog.coldfusionpowered.com/?p=110
$("#xxxxx").attr("selectedIndex")
source
http://blog.coldfusionpowered.com/?p=110
jQuery ~ hashchange event
今天做個在網址後面#多少就切過去的功能.....
用了張搞推薦的這個
這邊下載
http://github.com/cowboy/jquery-hashchange/raw/v1.3/jquery.ba-hashchange.min.js
放在jquery後
然後在他的事件裡打程式~~~~~看你要幹嘛~~~
很簡單使用吧A0A
source
http://benalman.com/projects/jquery-hashchange-plugin/
用了張搞推薦的這個
這邊下載
http://github.com/cowboy/jquery-hashchange/raw/v1.3/jquery.ba-hashchange.min.js
放在jquery後
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.ba-hashchange.min.js"></script>
<script type="text/javascript" src="js/jquery.ba-hashchange.min.js"></script>
然後在他的事件裡打程式~~~~~看你要幹嘛~~~
很簡單使用吧A0A
$(window).hashchange( function(){
var hash = window.location.hash;
var tabSelect = hash.substr(1, hash.length);
changeTab(tabSelect);
});
var hash = window.location.hash;
var tabSelect = hash.substr(1, hash.length);
changeTab(tabSelect);
});
source
http://benalman.com/projects/jquery-hashchange-plugin/
jQuery ~ hide table example
這個範例是當table裡面沒東西~~~~~
就把他hide~~~~並把前面的title (div)也hide
感謝張搞Q_Q
Javascript
HTML
就把他hide~~~~並把前面的title (div)也hide
感謝張搞Q_Q
Javascript
$(document).ready(function()
{
$('.list').each(function()
{
if($(this).find('tr').length == 1)
{
$(this).add($(this).prev()).hide();
}
});
});
{
$('.list').each(function()
{
if($(this).find('tr').length == 1)
{
$(this).add($(this).prev()).hide();
}
});
});
HTML
<div class="product_title">'.$product_name.'</div>
<table border="1" class="list" cellspacing="0" >
<tr class="top">
<td>Type</td>
<td>Name</td>
<td>Date</td>
<td>Download</td>
</tr>
</table>
<table border="1" class="list" cellspacing="0" >
<tr class="top">
<td>Type</td>
<td>Name</td>
<td>Date</td>
<td>Download</td>
</tr>
</table>
jQuery ~ get scroll top value
working on Firefox, Chrome, Opera, Safafi, IE
CSS
Javascript
------------------------------------------------------------------------------------------------------------------------------------
這段程式是我要固定某個東西在旁邊的功能~~固定的方式是用CSS的position:fixed
不會因為滾輪滑下去而看不到東西
主要是用$(window)
不然用$(document)在Opera跟IE會無作用= =
reference
http://api.jquery.com/scrollTop/
CSS
.fixed_map{
top:10px;
position:fixed;
}
top:10px;
position:fixed;
}
Javascript
$(window).scroll(function()
{
var y = $(window).scrollTop();
if(y > 280 )
{
$('#map-wrapper').addClass('fixed_map');
}
else
{
$('#map-wrapper').removeClass('fixed_map');
}
});
{
var y = $(window).scrollTop();
if(y > 280 )
{
$('#map-wrapper').addClass('fixed_map');
}
else
{
$('#map-wrapper').removeClass('fixed_map');
}
});
------------------------------------------------------------------------------------------------------------------------------------
這段程式是我要固定某個東西在旁邊的功能~~固定的方式是用CSS的position:fixed
不會因為滾輪滑下去而看不到東西
主要是用$(window)
不然用$(document)在Opera跟IE會無作用= =
reference
http://api.jquery.com/scrollTop/
jQuery ~ ScrollTo example
scroll in id="qqqq" div
scroll whole body
-----------------------------------code----------------------------------------------------------
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.scrollTo-min.js"></script>
<script>
function xxx()
{
$('#qqqq').scrollTo( { top:800, left:700}, 800 );
}
</script>
<button onclick="xxx()">sfsdfsdf</button>
<div id="qqqq" style="height:300px;width:500px;overflow:auto; border:1px #333 solid">
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
.....................................
</div>
-----------------------------------code----------------------------------------------------------
reference
http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
$('#qqqq').scrollTo( { top:800, left:700}, 800 );
scroll whole body
$.scrollTo( { top:800, left:700}, 800 );
-----------------------------------code----------------------------------------------------------
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="jquery.scrollTo-min.js"></script>
<script>
function xxx()
{
$('#qqqq').scrollTo( { top:800, left:700}, 800 );
}
</script>
<button onclick="xxx()">sfsdfsdf</button>
<div id="qqqq" style="height:300px;width:500px;overflow:auto; border:1px #333 solid">
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
<div >gggggggggggggggggggggggggggggggggggggggggg</div>
.....................................
</div>
-----------------------------------code----------------------------------------------------------
reference
http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
jQuery ~ change the img src
$('#mainImg').attr('src', 'img/card.png');
http://stackoverflow.com/questions/554273/changing-the-img-src-using-jquery
http://stackoverflow.com/questions/554273/changing-the-img-src-using-jquery
訂閱:
文章 (Atom)