如何在javascript中执行html标记

how to execute html tag in javascript

本文关键字:执行 html 标记 javascript      更新时间:2024-02-11

我的数据库通过在尖括号内插入命令来调用某些函数。即<SUBMIT title="Request Report">将创建一个按钮,将表单(标准)数据提交给引擎进行报告。

在点击该按钮之前,我想检查一些日期条件,这样我就在我的文档中插入了一个图像链接,该链接调用了我的javascript代码。如果满足所有条件,我希望它运行/单击上面的按钮。这是我的代码,在<提交>部分。欢迎提出任何建议。

function checkdate() {
    var currentTime = new Date();
    var startdate = document.forms[0].datescopestart.value;
    var startdate2 = startdate.split("/");
    var startdate3 = new Date(startdate2[2], startdate2[1] - 1, startdate2[0]);
    var totaldays = ((currentTime - startdate3) / 86400000);
    if (totaldays > 100) {
        alert("You can only choose a start date within the last 100 days")
    } else if (startdate == "") {
        alert("You cannot leave the start date blank")
    } else {
        ("<#SUBMIT>")
    }
}

编辑呈现<提交>按钮为:

<input type=button value="Request Report" class=button onclick="showhide('reportbutton');selectAll(document.forms[0].customfieldexp);selectAll(document.forms[0].user);document.forms[0].submit()">

我不知道如何将其合并到javascript中。

您想要执行与响应按钮的click()事件所执行的代码相同的代码。所以你需要编写这样的代码(它是重复的,有点脆弱,但你使用的框架没有给你太多的余地):

if (totaldays > 100) {
    alert("You can only choose a start date within the last 100 days");
} else if (startdate == "") {
    alert("You cannot leave the start date blank");
} else {
    showhide('reportbutton');
    selectAll(document.forms[0].customfieldexp);
    selectAll(document.forms[0].user);
    document.forms[0].submit();
}

我不知道showhide()和selectAll()是做什么的,所以你可能想研究一下代码,了解它们是如何作为提交的一部分的,正如你的框架所建立的那样。

风格注意:JavaScript解释器会自动在一行的末尾提供一个以分号结尾的语句,但依赖它不是一种好的做法。明确地对半决赛进行编码。