divが表示されたとき(showの後)に関数を呼び出したい。
誰かが私がこれをどのように行うことができるか知っていますか?私はそのようなものを使おうとします:
$(#someDiv).bind('show',function(){
alert('example')
});
しかし、私がそれを正しい方法で行っているのか、それともそれが可能であるのか、それとも達成できないのかはわかりません。何か案は?
次のコード(http://maximeparmentier.com/2012/11/06/bind-show-hide-events-with-jquery/から採用)を使用すると、を使用できるようになります$('#someDiv').on('show', someFunc);
。
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
el.apply(this, arguments);
return el;
};
});
})(jQuery);
これは、show()メソッドのポストコールバックで実行する必要があります。
$('#someDiv').show('slide',function(){
alert('example')
});
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script>
$(document).ready(function(){
$("#jq_message").show(function(){
$("#jq_message").fadeOut(3000);
$("#div2").fadeOut("slow");
$("#div3").fadeOut(3000);
});
});
</script>
<div id="jq_message">
</div>
$('#element').live('show', function(){
// CODE
});
私はこれを使います
$(document).on("pagebeforeshow", "#elementID", function ()
{
//Whatever
});
jQuery 1.7以降、.live()メソッドは非推奨になりました。.on()を使用して、イベントハンドラーをアタッチします。古いバージョンのjQueryのユーザーは、.live()ではなく.delegate()を使用する必要があります。
これを試して
$(#someDiv).bind('show',function(){
callFunction();
});
また
$(#someDiv).on('show',function(){
callFunction();
});
function callFunction(){............}