Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 占位符不显示_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 占位符不显示

Javascript 占位符不显示,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我做了一些jquery验证,我希望当用户退出input并且没有写东西时,一些文本显示为placeholder 我写了这段代码 $('input[type="text"]').on('blur', function() { if ( !!$(this).val() ) { $(this).css({ 'border': '#ff8383 1px solid' }); $(this).attr('placeholder'

我做了一些jquery验证,我希望当用户退出
input
并且没有写东西时,一些文本显示为
placeholder

我写了这段代码

$('input[type="text"]').on('blur', function() {
    if ( !!$(this).val() ) {
        $(this).css({
            'border': '#ff8383 1px solid'
        });
        $(this).attr('placeholder', 'this field is required');
    }
    else {
        $(this).css({
            'border': '#c3c3c3 1px solid'
        });
        $(this).attr('placeholder', '');
    }
});
它在chrome开发工具中工作
,但它不会出现在页面上。

这可能就是问题所在;在if语句中有两个刘海

 if ( !!$(this).val() ) {

这可能就是问题所在;在if语句中有两个刘海

 if ( !!$(this).val() ) {

您有一个额外的
此处:

 !!$(this).val()
您可以在相同的
(此)
中加入
css
attr

$('input[type=“text”])。在('blur',function()上{
if(!$(this.val()){
$(this.css)({
“边框”:“ff8383 1px实心”
}).attr('占位符','此字段为必填项');
}否则{
$(this.css)({
“边框”:“C3C3 1px实心”
}).attr('占位符','');
}
});

您有一个额外的
此处:

 !!$(this).val()
您可以在相同的
(此)
中加入
css
attr

$('input[type=“text”])。在('blur',function()上{
if(!$(this.val()){
$(this.css)({
“边框”:“ff8383 1px实心”
}).attr('占位符','此字段为必填项');
}否则{
$(this.css)({
“边框”:“C3C3 1px实心”
}).attr('占位符','');
}
});

起初我只写了一个“!”,但if语句不起作用。那是因为我的html中有value=”“。你们给了我一个线索。起初我写了一首单曲“!”,但若语句不起作用。那是因为我的html中有value=”“。你给了我一个线索。