Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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 使用条件on值更改div颜色_Javascript_Jquery_Html_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 使用条件on值更改div颜色

Javascript 使用条件on值更改div颜色,javascript,jquery,html,css,twitter-bootstrap,Javascript,Jquery,Html,Css,Twitter Bootstrap,我需要帮助,我有这样的div <div id="namacoc" tabindex="1" class="filled-text" placeholder="Input your name" contenteditable ></div> <div id="position" tabindex="1" class="filled-text" placeholder="Input your position" contenteditable></div&g

我需要帮助,我有这样的
div

<div id="namacoc" tabindex="1" class="filled-text" placeholder="Input your name" contenteditable ></div>
<div id="position" tabindex="1" class="filled-text" placeholder="Input your position" contenteditable></div>    
<button type="button" id="btncontinue" class="btn btn-wide btn-blue">Continue</button>

继续
我的问题是,我想检查
div
是否与验证类似。 示例:如果
namecoc
没有
<当我选择另一个div或按下按钮时,当namecoc的值将更改为正常颜色(黑色),code>div namecoc将改为红色

注意:我使用的是div,而不是input form,因为引导程序在激活时不会更改我的文本背景色。所以我使用的是
div

对不起,我的英语这么差

我建议您只使用
input
,内容编辑在不同的浏览器中确实存在问题

像这样试试。

$(“#btnConcontinue”)。单击(函数(){
$(“输入”)。每个(函数(){
$.trim($(this.val())==“”?
$(this.addClass(“无效”):$(this.removeClass(“无效”);
});
});
$(“输入”)。关于(“模糊”,函数(){
$.trim($(this.val())==“”?
$(this.addClass(“无效”):$(this.removeClass(“无效”);
});
。无效{
边框:红色1px实心;
}

继续
Array.prototype.forEach.call(document.queryselectoral(“.filled text”),函数(节点){
node.onfocus=函数(){
this.className+=“活动”;
var text=this.innerHTML;
如果((this.id==“namacoc”&&text==“输入您的姓名”)||
(this.id==“位置”&&text==“输入您的位置”)){
this.innerHTML=“”;
}
};
node.onblur=函数(){
this.className=this.className.replace(“活动”和“”);
如果(this.innerHTML==“”){
如果(this.id==“NAMAC”){
this.innerHTML=“输入您的姓名”;
}否则{
this.innerHTML=“输入您的职位”;
}
this.className=this.className.replace(“正常”、“空”)+“空”;
}否则{
this.className=this.className.replace(“空”、“正常”)+;
}
};
});
。填充文本{
宽度:200px;
填充:8px;
利润率:24px0;
边框:1px实心#000;
}
.filled-text.placeholder{
颜色:#D0;
}
.filled-text.empty{
颜色:红色;
}
.filled-text.active,
.filled-text.normal{
颜色:#000;
}
输入您的姓名

输入您的位置
,但当我填充div并选择另一个div时仍然是红色:(@Wolfzmus您是否尝试将上述逻辑用于divs?我希望对blur进行验证,然后我们可以修改上述代码。@Wolfzmus:)很高兴Help@PankajParkar字体你看了我的便条,我不能使用输入,因为引导不允许我创建新样式。