控制台或 JsLint 中不会弹出“真正的”错误。$("#buttonID1").click()
我个人更喜欢在 HTML 中使用 onclick,但作为调试的一部分我切换到了。我不知道代码有什么问题。现场版在这里DEMO
输入:Amazon_Laser_BobtheBodyBuilder_07-11-13.xls
预期输出:|-\n| 亚马逊\n| 激光\n| BobtheBodyBuilder\n| 2013 年 7 月 7 日\n
实际输出:什么都没有!
JS
function emptyText() {
$('#textinput').val('');
$('#textoutput').val('');
}
$("#buttonID1").click(function(){
var input = document.getElementById('textinput').value;
var lines = input.split('\n');
var output = '';
$.each(lines, function(key, line) {
var results = line.split(/[_\.]/);
if(results!==null && results.length!== 0)
{
var a = '|-\n| '+results[0]+'\n';
var b = '| '+results[1]+'\n';
var c = '| '+results[2]+'\n';
var d = results[3];
var e = '| '+results[4]+'\n';
var date = d.split(/[\-]/);
var mm = date[0];
var dd = date[1];
var yy = date[2];
var month = '';
switch(mm){
case "01":
month='Jan';
break;
case "02":
month='Feb';
break;
case "03":
month='Mar';
break;
case "04":
month='Apr';
break;
case "05":
month='May';
break;
case "06":
month='June';
break;
case "07":
month='Jul';
break;
case "08":
month='Aug';
break;
case "09":
month='Sep';
break;
case "10":
month='Oct';
break;
case "11":
month='Nov';
break;
case "12":
month='Dec';
break;
default:
break;
}
switch(yy){
case "10":
yy='2010';
break;
case "11":
yy='2011';
break;
case "12":
yy='2012';
break;
case "13":
yy='2013';
break;
default:
break;
}
var date2 = '| '+month+' '+dd+', '+yy+'\n';
output += a+b+c+date2+e;
}
});
});
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<link rel=href="https://dl.dropboxusercontent.com/u/101322542/Public%20Codes/mister%20table/Part%202%20-%20tokenizer/tokenizer.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script src="https://dl.dropboxusercontent.com/u/101322542/Public%20Codes/mister%20table/Part%202%20-%20tokenizer/tokenizer.js" type="text/javascript"></script>
</head>
<body>
<p class="left">Put your variables here:</p>
<textarea rows="4" cols="40" id="textinput">
</textarea>
<br>
<button type="button" id="buttonID1">AutoType</button>
<button type="button" id="buttonID2" onclick="emptyText()">Clear</button>
<p class="right">Output:</p>
<textarea rows="4" cols="40" id="textoutput">
</textarea>
</body>
</html>
CSS
#textinput{
background-color:#285c00;
color:white;
}
#textoutput{
background-color:#285c00;
color:white;
}