Javascriptをはじめ、Ajax、jQueryの著書多数のガイドが、何かと最近騒がれているJa…
Javascript関連情報
更新日:2007年11月18日
今回は、自作の関数を、jQuery側へ組み込んでみます。関数やオブジェクトをjQueryへ取り込み拡張しするための仕組みプラグインを利用します。
<script src="./jquery.js" type="text/javascript"></script>
<div id="testId">testIdです</div>
<script type="text/javascript">
jQuery.fn.sample = function() {
alert(this.text()) ; return this ;
};
$("#testId").sample(); //「testIdです」が表示されます
</script>
→サンプル
<script src="./jquery.js" type="text/javascript"></script>
<div class="testClass">DIVでtestClassです</div>
<div class="noTestClass">DIVでnoTestClassです</div>
<p class="testClass">PでtestClassです</p>
<script type="text/javascript">
jQuery.fn.drawRed = function() {
return this.css("color","red");
};
$("DIV.testClass").drawRed();
</script>
→サンプル
jQuery.fn.drawRed = function() {
return this.css("color","red");
};
$("DIV.testClass")
.drawRed()
.animate({fontSize: "5em"},1000 );
</script>
→サンプル 人気Javascriptランキング
Powered by 価格.com