在javascript中为文本框分配值 [英] Assign value to textbox in javascript
问题描述
$(function(){
document.getElementById( txtSearch)。 value = hai ;
});
< input class = width150 type = text id = txtsearch />
i有一个文本框。我想在jquery中为textbox赋值。但它显示这样的错误消息
未捕获TypeError:无法设置属性'value'为null
任何人都可以帮助我????
(function(){
document.getElementById( txtSearch)。 value = hai;
});
< ; input class = width150类型= text id = < span class =code-string> txtsearch />
i有一个文本框。我想在jquery中为textbox赋值。但它显示这样的错误消息
未捕获TypeError:无法设置属性'value'为null
任何人都可以帮助我????
你需要一个小写值和一个复数元素:
例如:
document .getElementsByName(' ContactEmail')[ 0 ]。value = email;
您需要[0]来获取列表中的第一个元素。名称不必像ids一样独特。\\ / blockquote>
它只是意味着找不到元素。如果它的id
值是txtSearch(检查它,应该是id =txtSearch
,并看看如何它在客户端使用原始HTML查找,使用查看页面源),jQuery选择器必须写为:
myElement =
$(function () { document.getElementById("txtSearch").value = "hai"; });
<input class="width150" type="text" id="txtsearch" />
i have a text box . I want to assign value to textbox in jquery. But its showing an error message like this
Uncaught TypeError: Cannot set property 'value' of null
Can anyone help me????解决方案(function () { document.getElementById("txtSearch").value = "hai"; });
<input class="width150" type="text" id="txtsearch" />
i have a text box . I want to assign value to textbox in jquery. But its showing an error message like this
Uncaught TypeError: Cannot set property 'value' of null
Can anyone help me????
You need a lower-case value and a plural Elements:
for example:
document.getElementsByName('ContactEmail')[0].value = email;
You need the [0] to get the first element in the list. Names don't have to be
unique like ids.
It simply means that the element was not found. If itsid
value is "txtSearch" (check it up, should beid="txtSearch"
, and see how it looks in raw HTML on the client side, using "View Page Source"), the jQuery selector must be written as:
myElement =
这篇关于在javascript中为文本框分配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!