1

这可能是一个非常愚蠢的问题,但我无法弄清楚该站点的 javascript 命令来根据文本字段是否实际填充来决定是否填充文本字段。我的代码在这里。

<html>
<head>
<title>Contact Us</title>
<link rel="stylesheet" type="text/css" href="main.css">
<style type="text/css">
#main-container{
padding-left: 3px;
padding-right: 3px;
}
#left-bar{
text-align: right;
}
#left-bar, #right-bar{
border: 2px solid gray;
}
#top-nav-bar{
border-top: 1px solid gray;
border-bottom: 2px solid gray;
border-left: 2px solid gray;
border-right: 2px solid gray;
}
#navTextn{
float: right;
padding-right: 20px;
padding-top:10px;
}
#navTextc{
float: right;
padding-right: 20px;
padding-top:10px;
}
#navTexth{
float: right;
padding-right: 20px;
padding-top:10px;
}
#Contus{
float:right;
padding-right: 30px;
padding-top:10px;
}
#logo{
height: 20px;
width: 100px;
padding-top: 10px;
padding left: 10px;
}


</style>
<script type="text/javascript">
    function validator(){
        if(document.mUs.bfinderm.text)
            alert("Thank you for your submission");
        else
            alert("No text has been entered");
    }
</script>


<title>Tickit</title>
</head>
<body id="body">
<div id="topline">
</div>
<div id="top-nav-bar">
    <a href="Homework.html"><image id="Logo" src="Tickit.png"></a>
    <a id="Contus" href="ContactUs.html">Us</a>
    <a id="navTextn">News</a>
    <a id="navTextc" href="Calendar.html">Calendar</a>
    <a id="navTexth" href="Homework.html">Home</a>
</div>
<table id="main-container">

    <tr>
        <td id="left-bar" valign="top">
            <a id="plinks" >Profile</a><br>
            <a id="plinks" >Mail</a><br>
            <a id="plinks" href="Homework.html">Work Stream</a><br>
            <a id="plinks" href="calendar.html">Calendar</a><br>
            <a id="plinks" href="Events.html">Events</a><br>
            </p>
        </td>
        <td id="main" valign="top">
        If you find any bugs with the website, please leave a message to us in the box below <br> <br>
            <form name="mUs">
                Message Us:<br> <input type="text" name="bfinderm" />
                <input type="button" value="Send" onClick="validator()" />
            </form>
        </td>
        <td id="right-bar" valign="top">

        </td>
    </tr>
</table>
</body>
</html>

就像在复选框中一样,validator() 代码将被选中

<script type="text/javascript">
    function validator(){
        if(document.stackflowrun.stflr.checked)
            alert("Yes it is checked!");
        else
            alert("Check that shit boul!");
    }
</script>

那么文本字段选项的等效验证器()命令是什么?

function validator(){
        if(document.mUs.bfinderm.text)
            alert("Thank you for your submission");
        else
            alert("No text has been entered");
    }
</script>

(文字不是这样)

4

5 回答 5

2

jquery:$("#youridhere").val()返回输入。添加:<script src="http://code.jquery.com/jquery-1.9.1.js"></script>使用jquery。把它放在你的<script>.

于 2013-10-25T01:31:01.420 回答
1

在 JavaScript 中:

if (document.getElementById("bfindem").value.length > 0)
{
               alert("Thank you for your submission");
        else
}
            alert("No text has been entered");
}

在 jQuery 中:

if ($("#bfindem").val().length > 0)
{
               alert("Thank you for your submission");
        else
}
            alert("No text has been entered");
}
于 2013-10-25T01:34:10.170 回答
1

使用value而不是text像这样:

function validator(){
        if(document.mUs.bfinderm.value)
            alert("Thank you for your submission");
        else
            alert("No text has been entered");
    }
于 2013-10-25T01:52:54.483 回答
0

使用 jQuery,修改你的函数,如下所示

function validator(){
    if($('input[name="bfinderm"]').val().length !== 0)
        alert("Thank you for your submission");
    else
        alert("No text has been entered");
}

jQuery 演示

使用直接的 Javascript,修改你的函数,如下所示

function validator(){
    if($('input[name="bfinderm"]').val().length !== 0)
        alert("Thank you for your submission");
    else
        alert("No text has been entered");
}

Javascript 演示

于 2013-10-25T01:38:15.250 回答
0

尝试 document.mUs.bfinderm.value - jquery 不需要

于 2013-10-25T01:47:18.233 回答