我有一个悬停事件应用于我的CSS输入文本字段,但我也有一个模糊事件应用于相同的元素。由于这两个事件不会同时发生,所以我认为使用两个事件是有意义的,并且在事件发生时具有完全不同的效果。不知何故,只有css活动到目前为止工作。但jquery之前工作,并且它停止工作,因为我添加了css部分。jquery mouseover与CSS悬停矛盾
为了更加震惊,在CSS中存在悬停事件,当鼠标悬停时,输入文本字段的边框将变为蓝色。但我也有jQuery中的另一个事件,当用户将负数放入输入文本字段中时,它将具有更改并且输入文本字段的边框将变为红色。 不知何故,jQuery的一部分不工作〜 帮助!!!!
HTML:
<div class="roundcorner">
<table>
<tr>
<th>Out of 100 points how would you score Governemnt performance for each section.</th>
<th>Most like to see increased</th>
<th>Most willing to see decreased</th>
</tr>
<tbody>
<tr>
<td id="p2">
<input type="text" name="name" />
</td>
<td id="i1">lakdksakdmksa</td>
<td id="d1">
<input type="radio" name="sex" />Yes</td>
</tr>
<tr>
<td id="p2">
<input type="text" name="name" />
</td>
<td id="i2">dsfwsedfwefwe</td>
<td id="d2">
<input type="radio" name="sex" />No</td>
</tr>
</tbody>
</table>
<div>
CSS:
.roundcorner {
border: 1px solid grey;
border-radius: 10px;
width: 100%;
overflow: hidden;
border-bottom: 0px;
}
.roundcorner table {
// border-collapse: collapse;
width: 100%;
border-spacing: 0;
overflow: hidden;
}
th {
background-color: #EEE;
padding: 10px;
border-right: 1px solid grey;
border-bottom: 1px solid grey;
border-collapse: collapse;
}
th:last-child {
border-right: 0px;
}
td {
text-align: centre;
//border: 1px solid grey;
border-right: 1px solid grey;
border-bottom: 1px solid grey;
border-collapse: collapse;
}
td:last-child {
border-right: 0px;
}
tr:hover {
background: #fafafa;
// font-weight:bold;
}
input[type=radio] {
vertical-align:middle;
margin-left: 45%;
margin-right: 45%;
}
input[type=text] {
width:20%;
height:20px;
margin-left:40%;
margin-right:40%;
border-radius:3px;
border: 1px solid grey;
}
input[type=text]:hover{
border: 1px solid #0066FF;
background-color: #FFFFFF;
}
td:first-child {
width: 25%;
height:60px;
}
td:nth-child(2) {
width: 50%;
text-align: center;
height: auto;
padding: 10px;
}
td:nth-child(3) {
width: 25%;
height:60px;
}
.inputbox {
border: 1px solid #8FDAFF;
background-color: #FFFFFF;
}
.error{
border: 1px solid red;
}
的javascript:
$(document).ready(function(){
$("input:text").blur(function(event){
if(event.which != 8){
if(document.getElementById($(this).attr("id")).value < 0){
alert("Please do no put negative number.");
document.getElementById($(this).attr("id")).value=0;
$(this).addClass("error");
}
}
});
});
更新的链接: http://jsfiddle.net/matildayipan/4hwwqr73/
的JS在你的榜样,如果CSS被删除甚至不工作。 – 2014-09-02 02:03:49
是的,我刚刚意识到它,但我不知道为什么这个JS部分不工作。 – 2014-09-02 02:05:27
问题的一部分是'document.getElementById($(this).attr(“id”))''。 'this'将是处理程序中的文本输入,并且您的任何输入都没有id。 – Bryan 2014-09-02 02:07:08