开发者

Span.innerHTML returns text but Span.value returns undefined?

开发者 https://www.devze.com 2023-03-13 23:57 出处:网络
I have a function that populates a pages with something like this <span id=\"span_title_\'+result_no+\'\">\'+title+\'</span>

I have a function that populates a pages with something like this

<span id="span_title_'+result_no+'">'+title+'</span>

and then I have another func开发者_C百科tion that has this:

      document.getElementById("span_title_"+which_table).innerHTML="asg";
alert(document.getElementById("span_title_"+which_table).value);

The strange thing is the first (innerHTML) call works perfectly, the second one, the alert, gives me "undefined"

Any idea why this is?


<span> DOM elements don't have a value property. Use innerHTML to read the contents.


span doesn't have attribute with the name "value" only innnerHTML, you should use innerHTML for second call.

0

精彩评论

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