javascript - 如何在新打开的窗口中设置文本框值?

标签 javascript jquery

我有以下 div,其中有一个文本框。

<div id="DvPrint">
    <div>
    <input type="text" style="width: 100px;
                                    margin-left: 25px;" class="textbox" id="ctl00_content_TxtLetterNumber" readonly="readonly" name="ctl00$content$TxtLetterNumber">
    </div>
    </div>

现在我使用 window.open 在新窗口中写入 div 内容。

 n = window.open('M80Print.aspx', '_blank', 'status=no,toolbar=no,menubar=yes,height=550px,width=640px');
            n.document.open();
 n.document.write($('#DvPrint').html());

现在我想更改新打开的窗口中的文本框值。我该怎么做?? 像这样的事情:

n.document.getElementById('ctl00_content_TxtLetterNumber').innerHTML = "1";

但它不起作用。

最佳答案

n.document.getElementById('ctl00_content_TxtLetterNumber').value = "1";

更改文本框值是通过 value 完成的,而不是通过 innerHTML 完成的。

jQuery:

$('#ctl00_content_TxtLetterNumber', n.document).val('1');

关于javascript - 如何在新打开的窗口中设置文本框值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10571680/

相关文章:

javascript - 如何用 "("和 ")"jQuery 替换 "<span>"和 "</span>"

javascript - 从javascript关闭firefox选项卡

javascript - 如果 xAxis 勾选,Highchart 数据标 checkout 现在中间

javascript - 在动态 JQuery 元素上设置动态数据

javascript - ajax发布/插入数据/行到谷歌电子表格

javascript - 粘性导航栏无法正常工作

javascript - ReactJS:尽管渲染了新元素,如何将元素固定到当前位置?

javascript - 在 QUnit 测试中,只有在测试运行之前获得引用时才会触发 click 事件

Jquery 的 "includedContent"+ SEO =?

jquery - 窗口调整大小不起作用