Several ways of js timing and plug-in variables are common (directly use js variables in jsp)

Several ways of js timing

     1,function show_tip(){

getTipData();

setTimeout("show_tip()",3000);

}

 

     2. Use the jquery plugin directly:

 

The context in jsp needs to use jsp-specific built-in objects such as (${pageContext.request.contextPath}),

It can only be recognized in jsp, but if js files like plugins need to use this, you can declare the above as variables in the global js of the jsp page,

The js plugin is loaded in this js. The code of the js plugin is quite written in jsp. Of course, this global variable can be used directly (which scripts are in front of the variable, and these scripts can be used directly)

 

Such as

In jsp:

The weburl variable can be used directly in jquery.message.offer.js

 

     <script>

var webUrl = "${pageContext.request.contextPath}";

$.getScript("${pageContext.request.contextPath}/resources/js/message/jquery.timer.js",////You can schedule here

function() {

$.getScript("${pageContext.request.contextPath}/resources/js/message/jquery.message.offer.js",//custom plugin function

function() {$.getScript("${pageContext.request.contextPath}/resources/js/message/jquery.form.js",//表单插件

function() {

$(".btnhr30").on('click',

function() {

checkCanBuy();

});

/* Get data every 3 seconds */

timermessageRecord = $ .timer (3000,

function() {

var count=infoCount(0);

   //alert(count);

if(count>0){

$("#button_messageRecord").val("消息("+count+")");

$("#button_messageRecord").fadeOut(100).fadeIn(100);////////////flickering effect

}

}); 

$(".class_customerNameSet").on('click',

function(){

switchCustomer(this);

}

);

//$(".class_customerNameSet").eq(0).click();

//checkmessageRecord(1);

});

});

});

 

 

</script>

 

 

jquery.timer.js:

     /**

 * jQuery Timer Plugin (jquery.timer.js)

 * @version 1.0.1

 * @author James Brooks <[email protected]>

 * @website http://james.brooks.so

 * @lit MIT - http://jbrooksuk.mit-license.org

 */

 

(function($) {

jQuery.timer = function(interval, callback, options) {

// Create options for the default reset value

var options = jQuery.extend({ reset: 500 }, options);

var interval = interval || options.reset;

 

if(!callback) { return false; }

 

var Timer = function(interval, callback, disabled) {

// Only used by internal code to call the callback

this.internalCallback = function() { callback(self); };

 

// Clears any timers

this.stop = function() { 

if(this.state === 1 && this.id) {

clearInterval(self.id); 

this.state = 0;

return true;

}

return false;

};

// Resets timers to a new time

this.reset = function(time) {

if(self.id) { clearInterval(self.id); }

var time = time || options.reset;

this.id = setInterval($.proxy(this.internalCallback, this), time);

this.state = 1;

return true;

};

// Pause a timer.

this.pause = function() {

if(self.id && this.state === 1) {

clearInterval(this.id);

this.state = 2;

return true;

}

return false;

};

// Resumes a paused timer.

this.resume = function() {

if(this.state === 2) {

this.state = 1;

this.id = setInterval($.proxy(this.internalCallback, this), this.interval);

return true;

}

return false;

};

 

// Set the interval time again

this.interval = interval;

 

// Set the timer, if enabled

if (!disabled) {

this.id = setInterval($.proxy(this.internalCallback, this), this.interval);

this.state = 1;

}

 

var self = this;

};

 

// Create a new timer object

return new Timer(interval, callback, options.disabled);

};

})(jQuery);

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326461981&siteId=291194637