如何避免prototype.js和实时搜索之间的冲突?现在我的搜索工作不正确。如果我删除prototype.js我的计数器不工作,但搜索工作正常。如何避免prototype和custom.js之间的冲突? (Custom.js已发布实时搜索代码)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/jquery.ez-bg-resize.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
//$.noConflict();
jQuery( document ).ready(function( $ ) { // JS for background size
$("body").ezBgResize({
img : "bg.jpg",
opacity : 1,
center : true
});
$("body").fadeIn("slow");
});
</script>
<script src="http://sportassveikata.lt/sveikata/js/prototypeplus.js" type="text/javascript"></script>
<script src="http://sportassveikata.lt/sveikata/js/skaic_index.js" type="text/javascript"></script>
<script src="http://www.kalorijos.lt/js/prototype.js" type="text/javascript"></script>
<script src="http://sportassveikata.lt/sveikata/js/custom.js" type="text/javascript"></script>
这是实时搜索代码:
/* JS File */
// Start Ready
jQuery( document ).ready(function( $ ) {
// Icon Click Focus
$('div.icon').click(function(){
$('input#search').focus();
});
// Live Search
// On Search Submit and Get Results
function search() {
var query_value = $('input#search').val();
$('b#search-string').html(query_value);
if(query_value !== ''){
$.ajax({
type: "POST",
url: "search.php",
data: { query: query_value },
cache: false,
success: function(html){
$("ul#results").html(html);
}
});
}return false;
}
$("input#search").on("keyup", function( e ) {
// Set Timeout
clearTimeout($.data(this, 'timer'));
// Set Search String
var search_string = $(this).val();
// Do Search
if (search_string == '') {
$("ul#results").fadeOut();
$('h4#results-text').fadeOut();
}else{
$("ul#results").fadeIn();
$('h4#results-text').fadeIn();
$(this).data('timer', setTimeout(search, 100));
};
});
});