我有两个 javascript 函数,如下所示,它们将计算 textareas 中的非空行。
HTML:
<div id="map-devlist" >
<div class="block-with-text-area">
<div class="input-quest-with-text-area">Enter your device list(one device in one line)</div>
<div class="input-resp-with-text-area"><span><textarea class="textarea" id="devs" name="devs" type="text" onkeyup="devscount();"></textarea></span> </div>
</div>
</div>
<div id="lunidlist" >
<div class="block-with-text-area">
<div class="input-quest-with-text-area">Enter your LUN IDs in Hex(one ID in one line)</div>
<div class="input-resp-with-text-area"><span><textarea class="textarea" id="lunids" name="lunids" type="text" onkeyup="luncount();"></textarea></span> </div>
</div>
</div>
<div id="error1"></div>
Javascript:
function devscount()
{
devcounts = 0;
var lines = $("#devs").val().split("\n");
for (var i = 0; i < lines.length; i++) {
if (lines[i].length > 0) devcounts++;
}
}
function luncount()
{
luncounts = 0;
var lines = $("#lunids").val().split("\n");
for (var i = 0; i < lines.length; i++) {
if (lines[i].length > 0) luncounts++;
}
if(devcounts == luncounts) {
var message ="both counts are matching";
} else {
var message ="Mismatch between values";
document.getElementById('error1').innerHTML=message;
}
}
现在我想比较这两个文本区域的行数,如果它们相等和不相等,我需要显示一条消息。但是上面的脚本对我不起作用。当我回 document.getElementById('error1').innerHTML=devscount;
显 document.getElementById('error1').innerHTML=luncounts;
它们相应的功能时,它完美地显示了行数。但我无法比较它们的值。怎么做 ?