<input type="text" style="width: 100%;height: 40px" id="subProjectAccount" name="subProjectAccount"
value="${item.subProjectAccount }" onblur="checkAmount(this)" />
</td>
<td >
<input type="button" value="删除" onclick="deleteTrShow(this)"/> <span id="typepro"></span>
</td></tr>
onblur事件中给<span>添加内容
function checkAmount(obj){
var amount = obj.value;
var reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
if(reg.test(amount)){
//这是准备给<span>中添加的提示
"<font style='color:green'>金额输入正确!</font>";
} else{
//这是准备给<span>中添加的提示
"<font style='color:red'>金额输入有误!请重新输入</font>";
}
}
怎么把那个提示加进去?求解答
4 个解决方案
#1
if(reg.test(amount)){
document.getElementById("typepro").innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
document.getElementById("typepro").innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
#2
忘了说: 我这个tr是动态添加的,可能有几个tr都相同,
<tr><td>
<input type="text" style="width: 100%;height: 40px" id="subProjectAccount" name="subProjectAccount"
value="${item.subProjectAccount }" onblur="checkAmount(this)" />
</td>
<td >
<input type="button" value="删除" onclick="deleteTrShow(this)"/><span id="typepro"></span>
</td></tr>
<tr><td>
<input type="text" style="width: 100%;height: 40px" id="subProjectAccount" name="subProjectAccount"
value="${item.subProjectAccount }" onblur="checkAmount(this)" />
</td>
<td >
<input type="button" value="删除" onclick="deleteTrShow(this)"/><span id="typepro"></span>
</td></tr>
你写的那个每次都是添加到第一个tr的span里
#3
span 的 id 改成 class
if(reg.test(amount)){
obj.parentNode.parentNode.getElementsByClassName("typepro")[0].innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
if(reg.test(amount)){
obj.parentNode.parentNode.getElementsByClassName("typepro")[0].innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
#4
$(obj).closest('tr').find('#typepro').html('xxxxxxxxxxxxxx');
#1
if(reg.test(amount)){
document.getElementById("typepro").innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
document.getElementById("typepro").innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
#2
忘了说: 我这个tr是动态添加的,可能有几个tr都相同,
<tr><td>
<input type="text" style="width: 100%;height: 40px" id="subProjectAccount" name="subProjectAccount"
value="${item.subProjectAccount }" onblur="checkAmount(this)" />
</td>
<td >
<input type="button" value="删除" onclick="deleteTrShow(this)"/><span id="typepro"></span>
</td></tr>
<tr><td>
<input type="text" style="width: 100%;height: 40px" id="subProjectAccount" name="subProjectAccount"
value="${item.subProjectAccount }" onblur="checkAmount(this)" />
</td>
<td >
<input type="button" value="删除" onclick="deleteTrShow(this)"/><span id="typepro"></span>
</td></tr>
你写的那个每次都是添加到第一个tr的span里
#3
span 的 id 改成 class
if(reg.test(amount)){
obj.parentNode.parentNode.getElementsByClassName("typepro")[0].innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
if(reg.test(amount)){
obj.parentNode.parentNode.getElementsByClassName("typepro")[0].innerHTML = "<font style='color:green'>金额输入正确!</font>";
} else{
#4
$(obj).closest('tr').find('#typepro').html('xxxxxxxxxxxxxx');