/*nice*/
顯示具有 JQuery 標籤的文章。 顯示所有文章
顯示具有 JQuery 標籤的文章。 顯示所有文章

2014年8月5日 星期二

Getting value of Select (dropdown) before change


var pre_value=0, value=0;
 $(".select").focus(function () {
     value = this.value;
 }).change(function() { 
  console.log("Pre_value="+value);
  pre_value = value;
  value = this.value;
  console.log("value="+value);
 });

ref : Here

2014年7月15日 星期二

.append(), ,appendTo(), .prepend(), .prependTo(), .after() and .before()

.append(), ,appendTo(), .prepend(), .prependTo(), .after() and .before()

有空來補範例

2014年7月7日 星期一

直接改變colorbox長寬的方法:resize

( 老爸如果本身是colorbox的話,也可使用 )
$(".iframe").colorbox.resize({width:"960px", height:"675px"});
ref:  Here

其它屬性設定,ref: Here

2014年7月2日 星期三

select change event get selected option

$('select').on('change', function (e) {
    var optionSelected = $("option:selected", this);
    var valueSelected = this.value;

    var parent = $(event.target).parent();
    ....
});

ref : Here and Here

2014年4月29日 星期二

自我學習 - pipe 範例

function func1() {
    var dfd = $.Deferred();
    setTimeout(function() {
    console.log("1");
	dfd.resolve(5);
    }, 3000);
    return dfd.promise();
}

function func2(x) {
    var dfd = $.Deferred();
    setTimeout(function() {
    console.log(x);
    dfd.resolve();
    }, 3000);
return dfd.promise();
}

function func3()
{
    console.log("3");
}

function bbb()
{
    func1().pipe(func2).pipe(func3).done(function(){
        console.log("finish");
    });
}

bbb();

2014年4月23日 星期三

自我學習 - Deferred and setTimeout範例

ref : 必看
ref : 範例二
var wait = function(xx){
    var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
    
    var tasks = function(yy){
      console.log("tasks-xx="+xx);
          console.log("tasks-yy="+yy);
          this.value=11;
    };

    setTimeout(function(){
        var ss=new tasks(31);
        console.log("ss="+ss);
        console.log("jason="+JSON.stringify(ss));
        dtd.resolve(); //改變Deferred對象的執行狀態
    },1500);
    
  return dtd.promise(); // 返回promise对象
  };
function bbb()
{
  $.when(wait(15))
  .done(function(){ 
      console.log("done"); 
      })
  .fail(function(){ console.log("fail"); });
    
    console.log("run...");
}

bbb();
ref : 範例一 + 比較好懂
function sayIt(ms, def) {
    setTimeout(function() {
        console.log('middle');
        def.resolve();
        console.log('middle-2');
        return 10;
    }, ms);
}

function slowPromise() {
    var def = $.Deferred();
    var result = sayIt(2000, def);
    return def;
}

slowPromise().then(function() {
    console.log('end');
});

2013年11月28日 星期四

筆記

初心者必看 -  jQuery 選取元素 (Selectors)

記錄一下一些語法:
  • $('#tab1').val()   //如果不能用,再查上面連結

2013年11月27日 星期三

多重 Class

命名時,id (#) 和 class (.) 最大不同點之一:
class可以同時套用數個


.applylarge 
{
   font-size:20px; 
}
.applyred
{
 color:#FF0000;
}
那以下的 HTML 碼,
<p class="applylarge applyred">多重 Class 的例子。</p>
就會顯現出,

多重 Class 的例子

ref: CSS Class 與 CSS ID

2013年11月3日 星期日

用Jquery寫個html的語法

這比我目前所會的Javascript拼拼湊湊快多了,也好maintain
(有空再貼個我土法練鋼的方法 = =")
作個紀錄
function a() {
    var $div = $("<div></div>");
    var $a = $("<a></a>")
        .attr("href", "#")
        .addClass("aClass")
        .text("Link text")
        .appendTo($div);

    $div.appendTo("#dinamicni_div");
}
ref: Here
/*nice*/