欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

form表单的提交(type="image" src="") input type image 有大用

下午看了一下代码,是一个关于用户注册的例子,但是怎么也找不到提交函数,既没有type=”button”,也没有type=”submit”
第一种

<form action="#" method="get" onsubmit="return checkForm();"> 
    <table align="center">
        <tr>
            <td>姓名:</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password"></td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="登录">
            </td>
        </tr>
    </table>
</form>
function checkForm(){
    var name = document.getElementsByName('name')[0].value;
    var pw = document.getElementsByName('password')[0].value;
    if( name != '' && pw != '' ){//用户名密码都不为空,则可以提交
        return true;
    }else{//否则不能提交
        return false;
    }
}


第二种

<form action="#" method="get" id="form1"> 
    <table align="center">
        <tr>
            <td>姓名:</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password"></td>
        </tr>
        <tr>
            <input type="button" value="登录" onclick = "checkForm();" />
        </tr>
    </table>
</form>
function checkForm(){
    var name = document.getElementsByName('name')[0].value;
    var pw = document.getElementsByName('password')[0].value;
    if( name != '' && pw != '' ){
        return true;
        document.getElementById("form1").submit();
    }else{
        return false;
    }
}

查了一下资料发现原来form表单提交还有一种方式,就是type=”image”加上src属性
下面的表单拥有两个输入字段以及一个图像形式的提交按钮:

<form action="#" method="get">
 <table align="center">
        <tr>
            <td>姓名:</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>密码:</td>
            <td><input type="password" name="password"></td>
        </tr>
        <tr>
            <input type="image" src="submit.jpg"/>
        </tr>
    </table>
</form>

src 属性只能与<input type="image"> 配合使用。它规定作为提交按钮显示的图像的 URL。
src 属性必须与 <input type="image"> 同时使用。


来自  https://blog.csdn.net/futureflyme/article/details/53161304

普通分类: