ASP:使用 getElementbyId 从 javascript 获取值

发布于 2024-10-06 04:56:01 字数 398 浏览 0 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静若繁花 2024-10-13 04:56:01

@mitesh:这里有一些示例代码应该会有所帮助 -

JavaScript:

var price = document.getElementById('Price');

ASP:

Dim iPrice
iPrice = Request.Form("Price")

HTML:

<input type="text" id="Price" name="Price" value="<%=iPrice %>">

@mitesh: Here's some sample code that should help --

JavaScript:

var price = document.getElementById('Price');

ASP:

Dim iPrice
iPrice = Request.Form("Price")

HTML:

<input type="text" id="Price" name="Price" value="<%=iPrice %>">
睡美人的小仙女 2024-10-13 04:56:01

只有输入值会在回发时传输回服务器,并使用name(而不是id)。 id 主要用于在 JavaScript 客户端中执行操作。

此外,在这两种情况下,getElementById 都将返回具有给定 id 的元素。然而,元素本身是不同的(跨度没有固有的)。此步骤可能需要更多的故障排除来确定“什么”不起作用。

Only input values are transmitted back to the server on a postback and the name is used (not the id). 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 inherent value). This step may require some more troubleshooting to determine "what" isn't working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文