Good evening everybody!

大家晚上好!

Well, I am studying JavaScript at the moment, and I reachead the point in where I need, based on clicked text (button, ... it doesn't matter, I guess).

嗯,我现在正在学习JavaScript,并且根据点击的文本(按钮,……)没关系,我猜)。

For example:

例如:

This message should be edited.

这个消息应该被编辑。

Two choices: ES - EN

有两种选择:ES - EN

If choice "ES" is clicked/selected, then:

如果选择“ES”被点击/选择,则:

This message has been edited to ES.

此消息已编辑为ES。

Otherwise, if choice "EN" is clicked/selected, then:

否则,如果单击/选择“EN”,则:

This message has been edited to EN.

此消息已被编辑为EN。

I think this could have been achieved with an if in a script, but the problem is how to tell the script which option has been chosen, if "ES" or "EN".

我认为这可以通过脚本中的if实现,但是问题是如何告诉脚本选择了哪个选项,如果是“ES”或“EN”。

I have this:

我有这个:

<p id="demo">This message should be edited.<p>
<a href="#" id="ES" onclick="func();">ES</a> - <a href="#" id="EN" onclick="func();">EN</a> - <a href="#" id="JP" onclick="func();">JP</a>

And as I said, the problem is that I don't know how to tell the script what has been clicked/selected.

正如我所说的,问题是我不知道如何告诉脚本什么被单击/选择了。

Thank you for any help you may give me (if possible, an explanation with or over a solution would be amazing because I want to learn and understand, not to solve this problem without being able to solve the same thing or similar in a future).

谢谢你给我的任何帮助(如果可能的话,有一个或多个解决方案的解释将是令人惊讶的,因为我想要学习和理解,而不是在未来无法解决同样的问题或类似的问题的情况下解决这个问题)。

6 个解决方案

#1


1

You can pass a argument to the function for example

例如,可以将参数传递给函数

function fun(lang){
    If(lang === "ES"){
        Do something 
    }else If(lang === "EN"){
        Do something 
    }
}

And when you call your function put something like this:

当你调用你的函数时可以这样写:

onClick="fun('ES')" or onClick="fun('EN')

onClick = "有趣(ES)”或onClick = "有趣(EN)

NOTE: instead of If 's you could use switch statement inside your function fun(lang)

注意:可以在函数fun(lang)中使用switch语句,而不是If 's

更多相关文章

  1. 通过脚本自动屏蔽非法IP(转http://bbs.5y6s.com/htm_data/21/080
  2. 在离开当前页面时调用函数。
  3. money_format()函数显示 而不是本地货币符号(磅)
  4. EL中的fn函数,jstl的fn函数,fn函数,fn函数描述,fn使用举例
  5. HTML5_旋转轮播-电子相册-新startMove函数写无缝轮播
  6. 深入剖析php执行原理(4):函数的调用
  7. php中的gethostbyname函数有问题
  8. JRoute::_() -函数在哪里?在joomla
  9. PHP通过系统命令执行Python脚本

随机推荐

  1. 第十一章:性能和可伸缩性——Java并发编程
  2. 在servlet中的init方法得到了对数据库操
  3. 轻量级javaEE SSH 01: 概述 环境与工具篇
  4. java时间转换,long , string和date和时间
  5. Java中PreparedStatement与Statement区别
  6. Java中的观察者模式
  7. Java连接Oracle数据库简单实例
  8. java集合框架系列-TreeMap介绍
  9. 八门神器 - GameKiller 中的防破解技术(附
  10. 看了“我们中应该有英雄”,也来愤青一下!