[英]jQuery/Javascript Button Text Change (EDIT!)
EDIT! 编辑!
I have a single button called "pc3LoadSELECT" that opens up a pop up with a new button called "loadCol_1" and loadCol_1 gets up to 150 options from local_storage. 我有一个名为“ pc3LoadSELECT”的按钮,它打开了一个带有名为“ loadCol_1”的新按钮的弹出窗口,并且loadCol_1从local_storage最多获取150个选项。
What I need to work out is how to get "pc3LoadSELECT" label SELECT to change to whatever value is present in loadCol_1. 我需要解决的是如何将“ pc3LoadSELECT”标签SELECT更改为loadCol_1中存在的任何值。
EG: If I choose 150 then the label SELECT will replace with 150. EG:如果我选择150,则标签SELECT将替换为150。
The 2 set's of code I have played around with are: 我玩过的两套代码是:
$('a[dsid="pc3FitmentSELECT"]').text("");
& 和
var listOfLabels = ['loadCol_1'];
function getRandomLabel()
{
return listOfLabels[Math.floor(Math.random() * listOfLabels.length) + 1];
}
$('a[dsid="pc3LoadSELECT"]').text("");
I will admit, in this 1 task I have been set, I am absolutely blind. 我承认,在完成这一项任务后,我绝对是盲目的。 So any help in attempting to work out or try to workout what is needed.
因此,在尝试锻炼或锻炼所需的一切帮助。
The data present isn't random and I shall attach an image which will show the range of options possible for this 1 button in the popup (a small sample). 出现的数据不是随机的,我将附上一张图片,该图片将显示弹出窗口中此1按钮的可能选项范围(一个小示例)。
Please advise? 请指教?
I created an example of a button that gets its value from an array. 我创建了一个按钮示例,该按钮从数组中获取其值。 Every time you open the popup you should set the button value from a list of options.
每次打开弹出窗口时,都应该从选项列表中设置按钮值。
for that i created the function getRandomLabel(); 为此,我创建了函数getRandomLabel();
hope that helps :) 希望能有所帮助:)
var listOfLabels = ['opt-1', 'opt-2', 'opt-3', 'opt-4', 'opt-5', 'opt-6']; function getRandomLabel() { return listOfLabels[Math.floor(Math.random() * listOfLabels.length) + 1]; } $('.randomize-label').click(function() { $('.btn1').html(getRandomLabel()); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button class="randomize-label">Randomize Label</button> <br> <br> <br> <br> <button class="btn1">SELECT</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.