jquery簡易メモ(1)-ベースレコード
2809 ワード
一、domオブジェクト及びjqueryオブジェクト相互変換
jqueryオブジェクトをdomオブジェクト、すなわち[index]とget(index)に変換
二、jqueryライブラリと他のライブラリの衝突
1. jqueryライブラリは他のライブラリの後にインポートされます
2.jqueryライブラリは他のライブラリの前にインポートされます
三、選択器の注意事項
「*」「#」「(」「[」などの特殊文字が含まれている場合は、エスケープに注意してください
jqueryオブジェクトをdomオブジェクト、すなわち[index]とget(index)に変換
:
var $j = $('#id'); // jquery
var j = $j[0]; // dom
:
var $j = $('#id'); // jquery
var j = $j.get(0); // dom
二、jqueryライブラリと他のライブラリの衝突
1. jqueryライブラリは他のライブラリの後にインポートされます
: jQuery.noConflict()
<script type="text/javascript" src = "prototype.js"></script>
<script type="text/javascript" src = "jquery.js"></script>
<script type="text/javascript">
jQuery.noConflict(); // $ , js
jQuery(function(){
jQuery("#uid").show(); // jQuery
})
$('id').style.display = 'none'; // js
</script>
:
var $j = jQuery.noConfilct();
$j(fucntion(){
$j('#uid').hide(); // jquery
})
$('id').style.display = 'none'; // js
: $
jQuery.noConflict(); // $ , js
jQuery(function($){ // jquery
$('#uid').show(); // $
})
$('id').style.display = 'none'; // js
: $ ,
jQuery.noConflict(); // $ , js
(function($){ // , $
$(function(){ // $ jQuery
$('#uid').show(); // $
})
})(jQuery); // , jQuery
$('id').style.display = 'none'; // js
2.jqueryライブラリは他のライブラリの前にインポートされます
jQuery, jQuery.noConflict() , js , $
<script type="text/javascript" src = 'jquery.js'></script>
<script type="text/javascript" src = 'prototype.js'></script>
<script type="text/javascript">
jQuery(function(){ // jQuery. jQuery.noConflict()
jQuery('#uid').show();
})
$('id').style.display = none ; // js
</script>
三、選択器の注意事項
「*」「#」「(」「[」などの特殊文字が含まれている場合は、エスケープに注意してください
<div id = "id#4"></div>
<div id = "id[4]"></div>
$('#id#4').show(); //
$('#id[4]').show(); //
$('#id\\#4').show();
$('#id\\[4\\]').show();