このコードは完全に機能しており、画像で事前入力フィールドをシミュレートしています。
<script>
$('#example).focus(function(){
var newValue = $(this).val();
if ($(this).val() == ""){
$(this).css("background-image", "none");
}else{
$(this).val(newValue);
}
}).blur(function(){
var newValue = $(this).val();
if ($(this).val() == ""){
$(this).css("background-image", "url(assets/templates/herveou-coiffure/css/pre_input.png)");
}else{
$(this).val(newValue);
}
});
</script>
いくつかの入力フィールド(少なくとも2つ)でこれを使用する必要があるので、次のようなことを試しました:
<script>
$('#example, example2').focus(function(){
var newValue = $(this).val();
if ($(this).val() == ""){
$(this).css("background-image", "none");
}else{
$(this).val(newValue);
}
}).blur(function(){
var newValue = $(this).val();
if ($(this).val() == ""){
if ($('#example2')[0]){
// Do something here if an element with this class exists
$(this).css("background-image", "url(assets/templates/herveou-coiffure/css/headers.jpg)");}
if ($('#example')[0]){
// Do something here if an element with this class exists
$(this).css("background-image", "url(assets/templates/herveou-coiffure/css/pre_input.png)");}
}else{
$(this).val(newValue);
}
});
</script>
もちろん、私はjavascritpの専門家ではなく、うまくいきません。誰でも助けてくれますか?? どうもありがとうございました...