开发者

What is the compatible JQuery line of code for IE7 and IE8?

开发者 https://www.devze.com 2023-01-02 00:50 出处:网络
This line of code is working fine for Firefox $(\"#<%=txt1.ClientID%>\").text(开发者_如何学Go)

This line of code is working fine for Firefox

$("#<%=txt1.ClientID%>").text(开发者_如何学Go)

but not for IE8 and IE7. See the scenario below in order to understand what I really mean:- Scenario:-

  1. Loading .aspx page.
  2. populating text box with some data from database.
  3. Now user changes data in same text-box at client-side (means page not yet submitted) So here in firefox, the above line of javascript is showing me the actual data came from database, but IE7&8 showing me the changed data. But I want actual data.

So i need some compatible code for IE7 & IE8

I hope i explained it well what i need. Thanks in advance


What's txt1? Is it an <input>?

Use input.value, or in jQuery val(), to read the value of a form field. text() reads textual content inside an element, which for most form fields is nothing.

For a <textarea> the textual content will be the initial contents of the field as in the source HTML file, not the current value of the field. (These initial contents correspond to the DOM defaultValue property, not value. In an <input>, this is the value="..." property instead of textual content, but it's still defaultValue in the DOM and not value.)


There's nothing about that snippet that would be incompatible with any of the IEs. Maybe you have a syntax error elsewhere that's breaking your code? For example, a list or hash defined with a trailing comma is a common IE-only error, if it appears anywhere in a <script> block it breaks the whole thing.


Your code snippet will capture the contents of the textfield at the time the code is executed.

This behaviour is the same on IE7,8 and Firefox.

Make sure your code is only been run on document.ready.

0

精彩评论

暂无评论...
验证码 换一张
取 消