我正在尝试使用星形图标更改我的表单(重力表单)中的数字(文本)“1”:
https://fontawesome.com/icons/star?style=regular
它必须像我猜的那样......
<script>
$("#label_13_5_0").text(function () {
return $(this).attr("1").text().replace("1", "star");
});
</script>
这不起作用
我的网站(你可以在我的表格中看到被星星取代的数字):
答案 0 :(得分:0)
也许这个,但我认为您需要安装fa图标
<script>
$("#label_13_5_0").text(function () {
return $(this).text("<i class='far fa-star'></i>");
});
</script>
但是以你的例子为例:
<script>
$("#label_13_5_0").text(function () {
return $(this).text("star");
});
</script>
答案 1 :(得分:0)
<!-- include fontawesome in your html -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
// --------------------------------------------------------
//
// 1) loop through the labels
// 2) get the text and convert it to number
// 3) create a string to hold the replacement html
// 4) make a while loop based on the number and add
// <i class="fa fa-star"></i> to the string on each
// loop the num-- will subtract one from number on
// each loop and cause it to stop at zero
// 5) replace the innerHTML with the icon markup
//
// --------------------------------------------------------
$('label', '.gfield_radio').each(function(){
var num = Number(this.innerText);
var str = '';
while(num--) str+='<i class="fa fa-star"></i>';
this.innerHTML = str;
});