2
如何填充文本输入的值?我正在尝试这种方式:填充输入文本
<input id="curso" maxlength="150" name="curso" size="40" type="text"
value="window.location.href.substring(91))" />
但这并不奏效。
如何填充文本输入的值?我正在尝试这种方式:填充输入文本
<input id="curso" maxlength="150" name="curso" size="40" type="text"
value="window.location.href.substring(91))" />
但这并不奏效。
<input id="curso" maxlength="150" name="curso" size="40" type="text">
<script>
document.getElementById("curso").value =
document.getElementById("curso").defaultValue = window.location.href.substring(91);
</script>
您无法从任意DOM属性中执行JavaScript。只有<script>
元素和事件处理程序可以包含JavaScript,因此请添加设置该值的<script>
。
您还需要设置defaultValue
属性,以便任何form reset将值重置为所需的值。
谢谢你的工作。 – Jean
作品http://jsfiddle.net/C2cQx/ –
嗨,我想从网址获得一个值,当我得到这个值,我必须把一个输入文本。例如,如果我创建一个按钮,把这onclic =“window.location.href.substring(91)”我得到我想要的,但我需要做的值=“window.location.href.substring(91) )“填写输入文字的文字 – Jean