javascript

Hagi 2012. 6. 5. 18:01

// This adds placeholder support to browsers that wouldn't otherwise support it.
$(function () {
if (!$.support.placeholder) {
var active = document.activeElement;
$(':text').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
}
});
$(':text').blur();
$(active).focus();
$('form:eq(0)').submit(function () {
$(':text.hasPlaceholder').val('');
});
}
});


또 다른 형식의 script 

// 입력값 안내문 설정
function inputvalueAttribute(element, attribute) {
var inputvalue = document.createElement(element);
if (attribute in inputvalue)
return true;
else
return false;
}
if (!inputvalueAttribute("input", "placeholder")) {
window.onload = function () {
    //쿠폰 번호 입력값 설정
var couponno = document.getElementById("<%=couponno.ClientID %>");
var couponno_content = "CP- XXXX-XXXX-XXXX-XXXX";

couponno.style.color = "gray";
couponno.value = couponno_content;

couponno.onfocus = function () {
if (this.style.color == "gray")
{ this.value = ""; this.style.color = "black" }
}
couponno.onblur = function () {
if (this.value == "")
{ this.style.color = "gray"; this.value = couponno_content; }
}
}
}