ASP:使用 getElementbyId 从 javascript 获取值
我正在尝试使用 getElementbyId 从 javascript 获取值,但我没有得到它。
如果我
<input type="text" id="disprice<% =pID %>" value="<%=disprice%>" name="Price" />
这样输入,那么我将从文本框中的 java 脚本中获取值。
但如果我尝试得到同样的东西,
<span class="productListPrice" id="disprice<% =pID %>">
那么我就得不到价值..
如果可能的话请帮助我。
米特什
I am trying to get value from javascript using getElementbyId but i am not getting it.
If i put,
<input type="text" id="disprice<% =pID %>" value="<%=disprice%>" name="Price" />
like this then i am getting value from java script in my text box.
But if i try to get that same thing like this,
<span class="productListPrice" id="disprice<% =pID %>">
then i am not getting the value..
Please help me if possible.
Mitesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的文本框需要一个 id。
更多详细信息 http://www.w3schools.com/jsref/tryit.asp?filename =tryjsref_doc_getelementbyid
Your texbox needs an id.
More details http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_getelementbyid
@mitesh:这里有一些示例代码应该会有所帮助 -
JavaScript:
ASP:
HTML:
@mitesh: Here's some sample code that should help --
JavaScript:
ASP:
HTML:
只有
输入
值会在回发时传输回服务器,并使用name
(而不是id
)。 id 主要用于在 JavaScript 客户端中执行操作。此外,在这两种情况下,
getElementById
都将返回具有给定 id 的元素。然而,元素本身是不同的(跨度没有固有的值
)。此步骤可能需要更多的故障排除来确定“什么”不起作用。Only
input
values are transmitted back to the server on a postback and thename
is used (not theid
). The id is primarily for doing things in JavaScript client-side.Also, in both cases,
getElementById
will return the element with the given id. However, the element itself is different (a span as no inherentvalue
). This step may require some more troubleshooting to determine "what" isn't working.