能否在 if 语句中调用 HTML 文档的 CSS 样式表
我试图在 if 语句中从 css 文件引入外部样式表。我有几个文本框,如果单击按钮,会弹出一个窗口,提示应填写整个表单并将背景颜色更改为红色。我的 HTML 文件中有这个:
<style type="text/css">
@import url("mysheet.css");
</style>
<script type="text/javascript">
function validateform()
{
var x=document.forms["CustInfo"]["Fname"].value;
if (x == null || x == "")
{
alert("The entire form must be filled out");
return false;
}
</script>
在我的 CSS 文件中,我只是有:
.formalert{
background-color: Red;
}
如何更改该“警报”以调用我的正式警报?
I am trying to bring in an external style sheet from a css file in an if statement. I have several textboxes and I need for if on the click of a button a pop up come up and it say the entire form should be filled and the background color change to red. I have this in my HTML file:
<style type="text/css">
@import url("mysheet.css");
</style>
<script type="text/javascript">
function validateform()
{
var x=document.forms["CustInfo"]["Fname"].value;
if (x == null || x == "")
{
alert("The entire form must be filled out");
return false;
}
</script>
In my CSS file I simply have:
.formalert{
background-color: Red;
}
How can I change that "alert" to call my formalert?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的简单方法是始终包含样式,但仅在验证失败时将表单设置为具有该 className。
The simple way to do this is to always include the style, but only set your form to have that className if it fails validation.