Without further ado, just add the real information. .
The specific code is as follows:
/*@@Intercept the string length, Chinese characters count 2 characters @@return [string]+'...'*/var subString = function(str, len) {var newLength = 0;var newStr = "";var chineseRegex = /[^/x00-/xff]/g;var singleChar = "";var strLength = str.replace(chineseRegex, "**").length;for (var i = 0; i < strLength; i++) {singleChar = str.charAt(i).toString();if (singleChar.match(chineseRegex) != null) {newLength += 2;} else {newLength++;}if (newLength > len) {break;}newStr += singleChar;}if (strLength > len) {newStr += "...";}return newStr;}------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- flag=false;$(".dialog_con").each(function(){if($(this).is(":visible")){flag=true;}})if(flag==true){$(".dialog_con").hide();$(".dialogbox").hide(); }else{ window.android.callAndroidFinish();}} --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- (/(iPad|iPod|iOS)/i.test(navigator.userAgent)) { setActiveStyleSheet("pad.css"); } else if (/(Android)/i.test(navigator.userAgent)) {setActiveStyleSheet("common.css"); }else if (/(iPhone6)/i.test(navigator.userAgent)) {setActiveStyleSheet("iphone6.css"); }function setActiveStyleSheet(filename){document.write("<link href="+filename+" rel=stylesheet>");}</script>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- or class to check whether a specific image is loaded. */$('img').load(function () {console.log('image load successful');});------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ This simple code can help a lot; @@Even if you don't have any broken links, adding this code will not have any effect. */$('img').on('error', function () {$(this).prop('src', 'img/broken.png');});---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- You can use the following code to add a class to the element when the user hovers; remove this class when the user's mouse leaves: */$('.btn').hover(function () {$(this).addClass('hover');}, function () {$(this).removeClass('hover');});----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Field @@ Sometimes you might want to make the form's submit button or its text input box unavailable until the user performs a specific behavior (such as the check box confirming "I've read this clause"). Add disabled attribute to your input and you can achieve the desired effect*/$('input[type="submit"]').prop('disabled', true);$('input[type="submit"]').prop('disabled', false);-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------/*@@Stop link loading@@Sometimes you don't want the link to jump to a page or reload the page, but hope to do something else, such as triggering other scripts. The following code is a trick to prohibit default behavior */$('a.no-link').click(function (e) {e.preventDefault();});-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Maybe you just want to show an element when the user clicks something, using fadeIn and slideDown is great. But if you want the element to appear on the first click and disappear on the second click, the following code can be done well */// Fade$('.btn').click(function () {$('.element').fadeToggle('slow');});// Toggle$('.btn').click(function () {$('.element').slideToggle('slow');});--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- panels$('#accordion').find('.content').hide();// Accordion$('#accordion').find('.accordion-header').click(function () {var next = $(this).next();next.slideToggle('fast');$('.content').not(next).slideUp('fast');return false;});---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Have the same height, no matter what they have in them: */$('.div').css('min-height', $('.main-div').height()); This example sets min-height, meaning it can be larger than the main div, but can never be smaller. But there is a more flexible way to iterate over the settings of a set of elements and set the height to the highest value in the element: var $columns = $('.column');var height = 0;$columns.each(function () {if ($(this).height() > height) {height = $(this).height();}});$columns.height(height); If you want all columns to have the same height: var $rows = $('.same-height-columns');$rows.each(function () {$(this).find('.column').height($(this).height());}); -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- '_self');------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- If the text does not exist, the element will be hidden: */var search = $('#search').val();$('div:not(:contains("' + search + '"))').hide();-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- else if (e.target.visibilityState === "hidden") {console.log('Tab is now hidden!');}});------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- But if the processing is not defined, other jQuery codes may stop working. You can define a global Ajax error handling through the following code*/$(document).ajaxError(function (e, xhr, settings, error) {console.log(error);});--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- See the following example code */$('#elem').show();$('#elem').html('bla');$('#elem').otherStuff();The above code can be greatly improved by chain operation: $('#elem').show().html('bla').otherStuff(); There is another method to cache elements in a variable (the prefix is $): var $elem = $('#elem');$elem.hide();$elem.html('bla');$elem.otherStuff();--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- traversal, select all, select non-select @@*////Select all, select non-select $('#checkAll').click(function () {//Judge whether it is selected var bischecked = $('#checkAll').is(':checked');var fruit = $('input[name="check"]');bischecked ? fruit.attr('checked', true) : fruit.attr('checked', false);});//Reversely select checkbox If it is currently selected, set to not select the same. The opposite is the same. $("#tabVouchList tr").each(function () {if ($("td:eq(0) input[name='check']", $(this)).is(':checked')) {$(this).attr('checked', false);} else {$(this).attr('checked', true);}});The above is a summary of js tips provided by the editor, I hope it will be helpful to everyone!