<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>
<script>
function formatHMStoS(value) {
var h, m, s = 0
if (value.indexOf("时") != -1) {
h = value.split("时")[0];
m = value.split("时")[1].split('分')[0];
s = value.split("时")[1].split('分')[1].split('秒')[0];
} else if (value.indexOf("时") == -1) {
if (value.indexOf("分") == -1) {
h=0
m=0
s = value.split('秒')[0];
} else {
h=0
m = value.split('分')[0];
s = value.split('分')[1].split('秒')[0];
}
}
var ss = h * 60 * 60 + m * 60 + s * 1;
return ss;
}
function a(value) {
document.getElementById("tar2").value = formatHMStoS(value);
}
</script>
</p>
<p>
<input id=hms value="2时3分5秒" />
<input type="button" value="时分秒===>秒" onClick="a(document.getElementById('hms').value)" />
<input type="text" id="tar2" />
</p>
</body>
</html>
以上代码新建html页面后全部替换即可运行
演示效果:
END