这是一个如何从元素中获取字符串数据、将其转换为整数并进行比较的示例。http://jsfiddle.net/svcH9/1/
$(document).ready(function () {
// get elements
var v1 = $('.value1').text(),
v2 = $('.value2').text();
// check requirements
if (isVersionString(v1) === true && isVersionString(v2) === true) {
// replace the v and cast to float
v1 = getVersion(v1);
v2 = getVersion(v2);
// test
$('body').append(v1).append(v2);
// simple compare
if (v1 < v2) {
alert('Value two is greater than value one');
}
}
});
function isVersionString(value) {
return /^v[0-9\.]{0,}$/.test(value);
}
function getVersion(value) {
return parseFloat(value.replace('v', ''), 10);
}