English 中文(简体)
Set x.inner Rainbow as INPUT truncating Valuestring
原标题:Set x.innerHTML as INPUT truncating value string
  • 时间:2011-03-20 12:14:52
  •  标签:
  • javascript

我已:

function edit(recRef)
{
var recID=recRef+ _what ;
var x=document.getElementById(recID);
var y=(x.innerHTML);
alert(y);
x.innerHTML="<INPUT type= text  value="+y+" />";
}

最初的计算指标是TD,在[例如“这一指示”]中作了说明。

在称号功能的末尾,INPUT tag型号在TD 标签内,但插号仅限第一字[例如,它显示的是“这一”而不是“这一指示”。

更令人感兴趣的是,如果在将INPUT tag的数值推高后,TD中的扼杀最初是空的,那就是一个单方的“/”。

这里正在发生什么?

最佳回答

而用的是:

var recID = recRef+ _what ;
var oRecord = document.getElementById(recID);
var sHTML = oRecord.innerHTML;
var oInput = document.createElement("input");
oInput.type = "text";
oInput.value = sHTML;
while (oRecord.childNodes.length > 0)
   oRecord.removeChild(oRecord.childNodes[0]);
oRecord.appendChild(oInput);

这将直接插入新的OM要素,而不是用字面的超文本。

问题回答

页: 1

x.innerHTML="<INPUT type= text  value= "+y+"  />";

Built atophil s response, heres what a cross browser Solutions may consider such as

function edit(recRef) {
    var isIE/*@cc_on=1@*/;
    var el = document.getElementById(recRef);
    var input = document.createElement( isIE ? "<input type= text >" : "input" );
    input.setAttribute("value",el.innerHTML)
    el.replaceChild(input,el.childNodes[0]);
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签