从字符串中获取数字并插入 css
get numbers from string and insert into css
我正在开发一个 javascript 函数,以便在名为 Intrexx 的开发平台上使用。它有其自身的局限性,但我相信下面的代码应该有效。
它应该获取数组中的数字,根据找到的内容计算百分比,然后 return 该百分比设置进度条的宽度。一切都按预期工作,除了设计部分的改变。有什么想法吗?
function progressBar(){
// get text of navigation (eg: 3 of 28)
var textProgress = document.getElementById('ID_navigationinfocontrolAB63A4D8').firstElementChild.innerHTML
// get numbers inside above string as array
var a = textProgress.match(/\d+/g).map(Number)
// take numbers in array, calculate percentage of progress, return int
var progressPercentage = parseInt((a[0]*100)/a[1])
// alter design of progress bar
var progressBarDesign = document.getElementById('ID_separatorcontrolC6F8BAC8').parentNode
progressBarDesign.style.width = progressPercentage +'% !important' }
我尝试直接编辑元素,但是这和编辑父节点都不起作用。
要设置重要,您可以使用以下语法
progressBarDesign.style.setProperty("width", progressPercentage + '%', "important");
或者,如果您可以不使用 important
,则当前语法应该可以正常工作。
progressBarDesign.style.width = progressPercentage + '%';
终于设法让它与 jQuery 一起工作。我不知道为什么这行得通而我的初始代码却行不通,但希望对其他人有所帮助。发布与第一次尝试的不同之处
// alter design of progress bar
var progressBarDesign =
document.getElementById('ID_separatorcontrolC6F8BAC8').parentNode
// initialize below function
setCss(progressBarDesign, 'width', progressPercentage + '%')
}
function setCss(oHtmlButton, cssKey, cssValue){
$(oHtmlButton).css(cssKey, cssValue);
}
我正在开发一个 javascript 函数,以便在名为 Intrexx 的开发平台上使用。它有其自身的局限性,但我相信下面的代码应该有效。 它应该获取数组中的数字,根据找到的内容计算百分比,然后 return 该百分比设置进度条的宽度。一切都按预期工作,除了设计部分的改变。有什么想法吗?
function progressBar(){
// get text of navigation (eg: 3 of 28)
var textProgress = document.getElementById('ID_navigationinfocontrolAB63A4D8').firstElementChild.innerHTML
// get numbers inside above string as array
var a = textProgress.match(/\d+/g).map(Number)
// take numbers in array, calculate percentage of progress, return int
var progressPercentage = parseInt((a[0]*100)/a[1])
// alter design of progress bar
var progressBarDesign = document.getElementById('ID_separatorcontrolC6F8BAC8').parentNode
progressBarDesign.style.width = progressPercentage +'% !important' }
我尝试直接编辑元素,但是这和编辑父节点都不起作用。
要设置重要,您可以使用以下语法
progressBarDesign.style.setProperty("width", progressPercentage + '%', "important");
或者,如果您可以不使用 important
,则当前语法应该可以正常工作。
progressBarDesign.style.width = progressPercentage + '%';
终于设法让它与 jQuery 一起工作。我不知道为什么这行得通而我的初始代码却行不通,但希望对其他人有所帮助。发布与第一次尝试的不同之处
// alter design of progress bar
var progressBarDesign =
document.getElementById('ID_separatorcontrolC6F8BAC8').parentNode
// initialize below function
setCss(progressBarDesign, 'width', progressPercentage + '%')
}
function setCss(oHtmlButton, cssKey, cssValue){
$(oHtmlButton).css(cssKey, cssValue);
}