gpt4 book ai didi

javascript - 通过内联 JavaScript 搜索表单提交帖子数据

转载 作者:行者123 更新时间:2023-11-28 08:34:32 25 4
gpt4 key购买 nike

我正在使用 GODADDY 电子邮件营销事件进行营销。在这里我可以使用设计器选项设计我自己的 html 模板。当我添加表单以提供搜索选项时,系统会自动从模板中删除表单标签,然后我无法从电子邮件中进行搜索。但我能够获取表单元素,例如输入文本框和提交按钮,但不能获取表单开始和结束标记。

为此,我计划编写一个内联 javascript 来将发布数据发送到搜索 url 。为此,我尝试了很少,但我不熟悉内联 JavaScript。

<input name="search" type="text">          

<input class="button" onclick="javascript:document.createElement('form');" type="submit" value="Go">

Javscript 模型(不基于我创建的想法工作)

function search() {
var theForm;
theForm = document.createElement('form');
theForm.action = 'search.php';
theForm.method = 'post';
var searchVal = document.getElementsByName('search').value;
newInput1.name = 'searchVal';
newInput1.value = searchVal;
theForm.submit();
}

预期的内联 JavaScript 是

 <input class="button" onclick="javascript: function(){ var theForm;        theForm = document.createElement('form'); theForm.action = 'search.php';  theForm.method = 'post'; var searchVal = document.getElementsByName('search').value; newInput1.name = 'searchVal';   newInput1.value = searchVal;theForm.submit();}" type="submit" value="Go">

最佳答案

如果你的系统确实允许你使用JS,试试这个:

HTML:

<input id="search" name="search" type="text">
<input class="button" onclick="search();" type="submit" value="Go">

JS:

 function search() {
var theForm;
theForm = document.createElement('form');
theForm.action = 'search.php';
theForm.method = 'post';
var searchVal = document.getElementById('search').value;
newInput1 = document.createElement('input');
newInput1.name = 'searchVal';
newInput1.value = searchVal;
theForm.appendChild(newInput1);
theForm.submit();
}

或内联:

<input id="search" name="search" type="text">
<input class="button" onclick="var theForm;theForm = document.createElement('form');theForm.action = 'search.php';theForm.method = 'post';var searchVal = document.getElementById('search').value;newInput1 = document.createElement('input');newInput1.name = 'searchVal';newInput1.value = searchVal;theForm.appendChild(newInput1);theForm.submit();" type="submit" value="Go">

关于javascript - 通过内联 JavaScript 搜索表单提交帖子数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21398465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com