仅在调用特定函数后如何触发JS脚本 [英] How to trigger a JS script only after a specific function is called

查看:62
本文介绍了仅在调用特定函数后如何触发JS脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,这是该问题的跟进, 如何保留通过JS onclick函数更改的innerhtml内容

basically this it a follow up of this question, How to keep the innerhtml content that is changed with the JS onclick function

所以我正确地解决了本地存储问题(这是上一个问题的解决方法),现在我需要触发此脚本,该脚本将innerhtml文本转换为匈牙利语,并且我都针对不同的语言创建了该脚本的不同版本:

So i got that local storage question right (that was the deal on the previous question), now i need to trigger this script which translates an innerhtml text to Hungarian and i all create different version of this script for different languages:

 ready(function(){
        if(localStorage.getItem('textSet')){
            document.getElementById("testchange").innerHTML = "Hungarian Lang"; //this part will change depending on language translations
        }
    })

上面的脚本由该脚本(下面的脚本)触发,在这种情况下,由于匈牙利语功能将文本翻译成该语言,导致其用于翻译,因此下面的脚本适用于匈牙利语或功能hungarianlang1(){ },所以我都有相同的意大利语或函数italianlang1(){}脚本,并调用了其翻译脚本(第一个脚本).

The script above is triggered by this one (the one below) in this case the Hungarian function since its translating a text to that language, cause its for translation purposes, so the script below is for hungarian or function hungarianlang1(){ } so i all have this same script for italian or function italianlang1(){ } and have its translation script (the 1st script) called.

function hungarianlang1() {
            document.getElementById("testchange").innerHTML = "Hungarian Call"; 
            //this will save the state of the change
            localStorage.setItem('textSet', true);
        }

所以我想有一个条件语句,该条件语句将根据所调用的语言函数(第二个函数),该条件的外观和任何想法触发第一个脚本. 谢谢

So i want to have a conditional statement, that triggers the 1st script depending on which language function is called (the 2nd function), how would that conditional look like, any ideas. Thanx

推荐答案

您的第一个函数看起来格式错误?您是否要调用名为ready的函数?

It looks like your first function is malformed? Are you trying to call a function called ready?

如果您使用的是jQuery,则在DOM准备就绪时设置回调的正确方法如下:

If you're using jQuery, the proper way to set a callback for when the DOM is ready is like so:

jQuery(document).ready(function() {
  // your code here
});

或者您可以使用速记:

$(function() {
  // your code here
});

这篇关于仅在调用特定函数后如何触发JS脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆