我使用了以下代码,其中我使用外部.js文件以及内联脚本函数。内联工作正常,标签更改为绿色但是当我在.js文件中放入相同的函数时,它显示错误的输出< / p>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="JScript1.js" type="text/javascript"></script>
<%--<script>
function onLeave1(_input, _labelInput) {
var char = /^[A-z]+$/;
var labelValue = _labelInput;
var check = _input.value;
if (_input.value.match(char)) {
$('.' + _labelInput).css("color", "green");
// var someVariable = document.getElementById("Label8").innerHTML;
// alert(someVariable);
}
else {
$('#Label8').css("color", "red");
}
}
</script>--%>
<style type="text/css">
.style1
{
height: 26px;
}
.style2
{
height: 26px;
width: 131px;
}
.style3
{
width: 131px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td class="style1">
<asp:Label runat="server" ID="lbl1" Text="First Name:-"></asp:Label>
</td>
<td class="style2">
<asp:TextBox ID="txtID2" runat="server" onblur="onLeave1(this,'Label8')"></asp:TextBox>
<asp:Label class="Label8" runat="server" Text="|" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
尝试改变:
$('#Label8').css("color", "red");
为:
$('.Label8').css("color", "red");
因为您已将class="Label8"
分配给您的标签