当我在表单输入文本框上使用 jquery$.removeAttr()
时,它会将文本框的大小调整大约 5 个像素。如果我不使用$.removeAttr()
,那么文本框将正常工作。什么是交易?
我最终试图从文本框中删除浅灰色斜体 CSS 样式并具有正常样式的黑色文本。
为什么我的文本框要调整大小?
html:
<style type="text/css">
.defaultText{
color: lightgrey;
font-style: italic;
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$('#email, #emailconfirm').live('focusin', function() {
if(this.value == 'Email' || this.value == 'Confirmation Email'){
$(this).val('').removeAttr('class');
}
});
});
<form id="newsletter" method="post" action="/mailist/?p=subscribe" name="subscribeform">
<input type="text" name="email" id="email" class="defaultText" value="Email" autocomplete="on" size="30"/><br/>
<script language="Javascript" type="text/javascript">addFieldToCheck("email","Email");</script>
<input type="text" name="emailconfirm" id="emailconfirm" class="defaultText" value="Confirmation Email" autocomplete="off" size="30"/><br/>
<script language="Javascript" type="text/javascript">addFieldToCheck("emailconfirm","Confirm your email address");</script>
<input type="submit" id="go" name="subscribe" value="Subscribe" onClick="return checkform();">
</form>