2011-10-05 28 views
3

我用下面的代碼把一個水印,這是位於水印的輸入框不能正常工作

,但在右下角的文本框中沒有顯示面具

<script language="javascript"> 
$(document).ready(function() { 
    $(":input[data-watermark]").each(function() { 
     $(this).val($(this).attr("data-watermark")); 
     $(this).bind('focus', function() { 
      if ($(this).val() == $(this).attr("data-watermark")) $(this).val(''); 
     }); 
     $(this).bind('blur', function() { 
      if ($(this).val() == '') $(this).val($(this).attr("data-watermark")); 
      $(this).css('color','#a8a8a8'); 
     }); 
    }); 
}); 
</script> 
<form onsubmit="setTimeout(function() {location.replace('./emails');},100)" name="ccoptin" action="http://visitor.r20.constantcontact.com/d.jsp" target="_blank" method="post"> 
    <div class="form-subscribe"> 
     <!--<div class="newsletter-lable"><label for="newsletter">Newsletter Sign-up:</label></div>--> 
     <div class="input-box"> 
      <input type="text" name="ea" title="Sign up for our newsletter" class="input-text required-entry validate-email" data-watermark="Type your email and subscribe"/> 
+2

你[真的有那個網站的麻煩](http://stackoverflow.com/search?q=www.theprinterdepo.com)不是你! – Bojangles

+0

不是真的,只有2件事。 –

回答

3

你使用像$(其結果爲ready)之類的jQuery函數,儘管你還沒有包含jQuery。這產生了錯誤(看到它在瀏覽器的控制檯F12):

Uncaught TypeError: Object #<HTMLDocument> has no method 'ready' 

包括jQuery的一個<script>元素你的JavaScript代碼之前,像這樣:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"> 
</script> 

另外,使用原型(你已經包括)的equivalent of document.ready

+0

我做到了,但是當放置該行菜單不再工作。 –