我如何使用JavaScript更改WordPress短码值
我正在使用watupro插件进行简单测试。在结果窗口中有一些变量显示数字测试结果:%%类别点-4 %%
,%%类别点-5 %%
等。
我正在使用进度条插件,以显示通过短代码结果的进度栏。 [WPPB Progress = %%类别点-4 %%/130选项= green]
根据学生在每个类别中的结果,给了我不错的进度栏。
但是,我想根据结果显示不同的进度栏。为了实现这一目标,我想根据数字值更改短代码的值。
到目前为止,我提出了此代码:
html:
<div class="bar" data-score="%%CATEGORY-POINTS-4%%">[wppb progress=%%CATEGORY-POINTS-4%%/130 option=green]</div>
<div class="bar" data-score="%%CATEGORY-POINTS-5%%">[wppb progress=%%CATEGORY-POINTS-5%%/130 option=green]</div>
<script type="text/javascript">
results();
</script>
javaScript:
function results() {
var bar = document.getElementsByClass('bar');
var score = bar.getAttribute('data-score');
alert (score);
if (score < 47) {
// ???
}
if (score > 46 && 4_score < 71) {
// ???
}
if (score > 70) {
// ???
}
我想我需要提出将快点属性option
分别为每个div的不同颜色的代码。
有什么想法吗?
I am using Watupro plugin for simple test. In result window there are variables that display numeric test results: %%CATEGORY-POINTS-4%%
, %%CATEGORY-POINTS-5%%
etc.
I am using Progress Bar plugin, to display progress bar with results via shortcode.[wppb progress=%%CATEGORY-POINTS-4%%/130 option=green]
gives me nice progress bar, based on student's results in each category.
However I want to display different colors of progress bar, depending on result. In order to achieve that, I want to change value of shortcode, based on numeric values.
I came up with this code so far:
HTML:
<div class="bar" data-score="%%CATEGORY-POINTS-4%%">[wppb progress=%%CATEGORY-POINTS-4%%/130 option=green]</div>
<div class="bar" data-score="%%CATEGORY-POINTS-5%%">[wppb progress=%%CATEGORY-POINTS-5%%/130 option=green]</div>
<script type="text/javascript">
results();
</script>
JavaScript:
function results() {
var bar = document.getElementsByClass('bar');
var score = bar.getAttribute('data-score');
alert (score);
if (score < 47) {
// ???
}
if (score > 46 && 4_score < 71) {
// ???
}
if (score > 70) {
// ???
}
I guess I need to come up with code that changes shortcode attribute option
to different color for each div respectively.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您正在使用WP,因此可以尝试这样的jQuery:
然后创建新的CSS类黄色:
Since you are using WP, you can try jQuery like this:
Then create new CSS class yellow:
好的。我解决了。
我添加了循环,因此,JavaScript经过所有Divs。
这里是代码:
工作示例: https://codepen.io/nick-io/nick-io/nick----- Gregory-the-looper/pen/wvympmg
Ok. I got it solved.
I added loop, so, Javascript goes through all divs.
Here's the code:
Working example here: https://codepen.io/nick-gregory-the-looper/pen/wvympmg