我有一个wordpress应用程序,<?php _e('foo', 'bar') ?>当我需要回显需要翻译的东西时,我通常会使用PHP函数.但是,现在我正在实现一个新功能,在我的.js文件中我有类似的东西
var confirmation = confirm("Are you sure you want to quit");
if(confirmation){
...
}
Run Code Online (Sandbox Code Playgroud)
上面代码的问题是我不能使用PHP函数_e()来翻译它,因为这是一个JS脚本.
反正有没有为JS中回应的文本翻译?
我提出了一个赏金,因为给出的问题是通用的,而我正在寻找可以解决我的问题的解决方案.
我正在研究之前由某人建造的WP项目.我应该只对存在于名为functions.jspath的js文件中的代码添加一个转换:C:\Users\meskerem\foo.com\wp-content\themes\foo\assets\scripts\functions.js让我们假设函数内部存在以下代码.
var confirmation = confirm("Are you sure you want to quit");
if(confirmation){
...
}
Run Code Online (Sandbox Code Playgroud)
现在的目标是使英语句子可以翻译.单击此文件中的按钮时,将执行上述js代码.
C:\Users\meskerem\foo.com\wp-content\plugins\wp-jobhunt\templates\dashboards\candidate\templates_ajax_functions.php
触发翻译的html代码非常简单:
<h1> <?= _e('good morning', 'jobhunt') ?> </h1>
<div> <i class='icon-trash' onclick="askConfirmation()"> x </i> </div>
Run Code Online (Sandbox Code Playgroud)
所以,脚本很简单,但翻译是我遇到问题的地方.
我有以下 html 结构
<div class='container'>
<div class='comment-row-id-1'> <span class='user'> job </span> <span class='icon-trash'> </span> </div>
<div class='comment-row-id-2'> <span class='user'> smith </span> <span class='icon-trash'> </span> </div>
<div class='comment-row-id-3'> <span class='user'> jane </span> <span class='icon-trash'> </span> </div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当用户单击具有“icon-trash”类的任何跨度时,我不想触发 onclick 响应。
我可以处理点击了哪个跨度,但现在我卡在点击本身上,因为它不是我在这个例子中无法收到警报消息
jQuery(".icon-trash").click(function(){
alert('hi')
})
Run Code Online (Sandbox Code Playgroud)