Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用脚本标记设置输入元素的属性值_Javascript_Html - Fatal编程技术网

Javascript 使用脚本标记设置输入元素的属性值

Javascript 使用脚本标记设置输入元素的属性值,javascript,html,Javascript,Html,我想在输入元素上设置如下值: <input type="submit" name="submit" id="loginButton" value="<script>document.write(language['login'])</script>"/> 但我不能让它工作。不可能吗?使用Javascript,您可以使用setAttribute函数将值赋予属性value 以下是一个可能的解决方案: var button = document.getElem

我想在输入元素上设置如下值:

<input type="submit" name="submit" id="loginButton" value="<script>document.write(language['login'])</script>"/>


但我不能让它工作。不可能吗?

使用Javascript,您可以使用
setAttribute
函数将值赋予属性
value

以下是一个可能的解决方案:

var button = document.getElementById("#loginButton"); //Select your button element
button.setAttribute("value","Your value to set"); //Set value attribute to your element

祝你好运

当然有可能,但不是那样。
是纯文本,您不能将脚本代码放在其中并期望执行。通过javascriptOk中的document.getElementById获取元素来设置此值,当然我知道这些不同的方法,但我只是想知道。我在想某种逃跑的办法,这样做是可能的,但不能这样做。谢谢你的回答。