将变量添加到属性

时间:2019-03-06 11:55:01

标签: javascript html forms

我需要将action的url属性由“ url” +变量组成。 像这样:

    <script>
    var domain = "@example.com";
    </script>
    <body>
    <form action=("https://login.example.com/&" + domain) id="login_form" method="get">
    <input type="text" name="username">
    <button type="submit" id="submit">Log in</button>
    </form>

我需要使用姓氏制作标签,并通过此表格将标签发送为lastname@example.com。

4 个答案:

答案 0 :(得分:2)

您可以尝试

{{1}}

答案 1 :(得分:0)

使用document.querySelector获取表单元素。使用setAttribute将变量添加到action属性,并将其赋予表单

    var domain = "@camosoft.cz";
    var a=document.querySelector('form').getAttribute('action');
    document.querySelector('form').setAttribute('action',a+domain);
    <body>
    <form action="https://login.szn.cz//?returnURL=https://email.seznam.cz/&serviceId=email&" + domain id="login_form" method="get">d</form>

答案 2 :(得分:0)

页面加载后,您可以借助Javascript动态设置表单操作。

示例:

date

答案 3 :(得分:0)

您必须连接字符串,然后通过JavaScript(而不是内联在HTML中)设置最终值。

此外,将Fiori Launchpad元素放在结束script标记(body)的前面,以便在解析器到达它时,所有HTML都将被解析到内存中。

最后,HTML中围绕属性值的括号不正确。

</body>

相关问题