我有一個懸停事件應用於我的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