Javascript中的html

Javascript中的html,javascript,action,Javascript,Action,如何使用变量将参数输入到动作标记? 例如: var actionurl=“一些url” windowhandle.document.write(“您没有在表单中设置actionurl的值。请尝试以下操作: windowhandle.document.write('<form name=sample action=' + actionurl + 'method="post"> </form>'); windowhandle.document.write(“”); 编辑:

如何使用变量将参数输入到动作标记? 例如:

var actionurl=“一些url”

windowhandle.document.write(“您没有在表单中设置
actionurl
的值。请尝试以下操作:

windowhandle.document.write('<form name=sample action=' + actionurl + 'method="post"> </form>');
windowhandle.document.write(“”);

编辑:您还缺少我现在添加的“>”。

您没有在表单中设置
actionurl
的值。请尝试以下操作:

windowhandle.document.write('<form name=sample action=' + actionurl + 'method="post"> </form>');
windowhandle.document.write(“”);
编辑:您还缺少我现在添加的“>”。

尝试以下操作:

var actionurl="some url"
windowhandle.document.write('<form name=sample action='+ actionurl +' method="post" </form>');
windowhandle.document.sample.submit();
var actionurl=“一些url”
windowhandle.document.write(“尝试以下操作:

var actionurl="some url"
windowhandle.document.write('<form name=sample action='+ actionurl +' method="post" </form>');
windowhandle.document.sample.submit();
var actionurl=“一些url”

windowhandle.document.write(“您可以使用Python的
.format()
函数:

String.prototype.format = function() {
    var str = this;
    var i = 0;
    var len = arguments.length;
    var matches = str.match(/{}/g);
    if( !matches || matches.length !== len ) {
        throw "wrong number of arguments";
    }
    while( i < len ) {
        str = str.replace(/{}/, arguments[i] );
        i++;
    }
    return str;
};
它只是用函数的参数替换括号内的子字符串

现在,您的新代码如下所示:

var actionurl="some url"
windowhandle.document.write('<form name="sample" action="{}" method="post"></form>'.format(actionurl));
windowhandle.document.sample.submit();
var actionurl=“一些url”
windowhandle.document.write(“”.format(actionurl));
windowhandle.document.sample.submit();

确保在属性周围使用引号!

您可以使用Python的
.format()
函数:

String.prototype.format = function() {
    var str = this;
    var i = 0;
    var len = arguments.length;
    var matches = str.match(/{}/g);
    if( !matches || matches.length !== len ) {
        throw "wrong number of arguments";
    }
    while( i < len ) {
        str = str.replace(/{}/, arguments[i] );
        i++;
    }
    return str;
};
它只是用函数的参数替换括号内的子字符串

现在,您的新代码如下所示:

var actionurl="some url"
windowhandle.document.write('<form name="sample" action="{}" method="post"></form>'.format(actionurl));
windowhandle.document.sample.submit();
var actionurl=“一些url”
windowhandle.document.write(“”.format(actionurl));
windowhandle.document.sample.submit();

请确保在属性周围使用引号!

不要忘记“post”之后的>,比如:“@onitake-是的,我已经修改了。不要忘记“post”之后的>,比如:“@onitake-是的,我已经修改了。我知道。这是
.format()的JavaScript实现
来自Python。我认为OP想要一种不使用加号将字符串插入其他字符串的方法。我知道。这是Python的
.format()
的JavaScript实现。我认为OP想要一种不使用加号将字符串插入其他字符串的方法。感谢大家。它工作得很好:)太好了。请接受答案:)看每个选项左边的勾号。谢谢大家。它工作得很好:)太好了。请接受答案:)请看每个答案左边的勾号。